C :: Printing Sum Of Variables From Array Of Structure?
Oct 10, 2014
I have an array of structure that takes family information (name, age, and state) after it takes the users input it prints back all of the information that was input and then prints the family members that just live in Texas. After that I am trying to implement a function to average out the ages of all family members but I cant seem to get it right, whenever it gets to that part of the program it just outputs 0. I also tried adding an & sign prior to FAMILY[i].age and got an error of int from ptr with no cast.
Also I realize that the code only shows adding of the family members ages which is fine for now as I am concentrated on getting that to work in the first place.
Im trying to run my program and it works fine until the very end where I want it to read "<name> is a <gender> citizen of <nation>." with the corresponding variables. Here is my work for the time being. Also is there a way to make it where if someone puts a M or m for gender, it will spit out Male instead of just m or M.
#include <iostream> using namespace std; int main() { char gender;
I have kept dummy as the data to be aligned.I will update hours, minutes, and seconds , but will not use dummy in any case. If I don't initialize 'dummy' does it make any errors ? Do I need to initialize hours, minutes, seconds as well before I use the structure ? If so is there any particular reason ?
I have a project for class where I have to create a structure and get user input for 3 structure variable arrays of 10. I am trying to figure out how I can use the same function to fill my different section of variables.
My Structure is an employee file of ID number, name, hours, payrate, and then gross pay. I have to create a function for each input function. I am confused on how to pass the structure variable so that I do not have to write 3 functions for each input. I would like to be able to get all the info for the first structure variable and then recall the same 5 functions for the next before moving along. I hope that I have been able to make this clear. Here is my code:
I have an array, ary[size+1] and the original values entered and then another value, x, entered. I found the index of x that makes the array nondecreasing order
Code:
void InsertX (int ary[], int size, int x) { int i=0; int j; int index; while(ary[i]<x)
[Code]...
But i can't figure out how to print the new array with x in it, using its index
how to print a box using 2d arrrays. i have to create a tetris game which a im stuck at this stage... so far i have tired i can only come out with this..my coding done so far is as follows:
Example : Code: struct x { int v[4]; }; const x test = { 0, 1, 2, 3 };
Why can I do this? How does the compiler know to write to this in the proper way? I get that v would be contiguous. Does that have something to do with it?
I want to make a program that asks the user for a message and then print out a large graphic of that message. For example, if the user types "he" I want to print out
H..................H EEEEEEEEE H..................H E H..................H E H..................H E HHHHHHHHHH EEEEEEEEE H..................H E H..................H E H..................H E H..................H EEEEEEEEE
(treat the periods as spaces. I only put them there because it wouldn't separate the H's correctly.)
I will loop this to continue until the user types quit.
1. How would I set this up to store the user input characters into an array?
2. How would I print out the stored data in the shape of the word?
I am trying to print out prime from array. I have viewed other sources that are similar and tried to use as reference, but only to confuse myself. This is what i have so far.
void get_output(int&Max,int array[]) { //array[i]-i; for(i=1;i<=10;i++) // allow 10 outputs on a line. { for(int i=0;i<Max;i++) { prime=true;
I am writing a code with C where I will give an integer and get the binary conversion of it.I tried to fill the binary digits into an integer array.But when I normally print it will give the proper output.But when I try to print the contents of the array it will not produce the proper result.
I have a program where I need to read in a 96 number .txt file and perform some operations on it.However, the numbers it reads in are all inncorrect. I got it to work in XCode, but it doesnt work in DevC++ which is where the teacher will be running it. Do I have any major error?
I'm having some trouble printing the duplicates found in an array. Specifically, when the value is at more than 2 positions. So if the value 3 is at position 1, 10, and 11 it'll print three messages instead of two:
value 3 at position 1 is also at position 10 value 3 at position 1 is also at position 11 value 3 at position 10 is also at position 11
instead of
value 3 at position 1 is also at position 10 value 3 at position 1 is also at position 11
This is real simple problem, but I can't seem to figure it out. I've been trying to implement another array to 'remember' the encountered position, but I haven't had any luck.
Code: for(i = 0; i < num_count; i++){for (j = i + 1; j < num_count; j++) {if (num[i] == num[j]){printf(" value %d at position %d is also at position %d", num[i], i, j);}}}
i'd like to ask if it's possible to fill every array in structure to zero. (Without using too much cycles)Something like this (I know that it doesn't work):
I am doing a data structures program on C++ that is suposse to consist of declaring an array of size five for my credit card structure, that allows the user to input information of five diferent credit cards. I am having a problem with my program, because it runs but after I input the information of the credit card, it does not print out the values that I had input.I dont know where I went wrong with the code or if it is that my approach to solving it is wrong. My code is the following:
I'd have to print the elements in italics. I've tried this:
for (i = 1; i < a.GetLength(0); i++) { for (j = i-1; j >=0; j--) Console.Write("{0,-2}", a[i, j]); Console.WriteLine(); }
with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.
Ok, so this assignment is to create a structure that allows input for up to 6 employees that then makes a 6 structure array showing Employee ID, Employee Last Name, Employee Pay Rate, Employee Hours Worked, Employee Pay, and Total Gross Pay for All Employees.
I don't have a printf yet for total gross, but right now I am just trying to tackle the input. Obviously I am not doing it right because although gcc complier is not giving errors the program is not ending when I type 'q' (sentinel issue) or when I reach 6 employees. It just continues input forever. Here is my code so far:
Code: //Cameron Taylor #include <stdio.h> #define MAXARRAY 6 struct Record{ int idnum; char lname[20]; double pay_rate;
i need to print the names as they appear in the original file, print the info of the person with the highest distance, print the info sorted by ascending ID number, and print sorted by name alphabetically. the first two parts work fine but sorting by ID and Name dont work.
I have two variables t and x in an array that alternate. I want to add two t's and find the average and then do the same for the x's. After that, I want to find the slope of x -> t. My problem is that I specify the n for t, but since it's local I can;t use it for the slope. Here's my code so far:
#include <iostream> using namespace std; int main() { double PA [8] = {0.0001234, 1.0005434, 0.0005678, 1.0023423, 0.00063452, 1.0001546, 0.00074321, 1.00017654};
[Code] ....
And, can I actually use the n2 as an index, or will the processor not understand that?
i j x y w h w*h 0 0 0 0 9 11 99 1 0 0 11 9 10 90 2 0 0 21 9 11 99 0 1 9 0 8 12 96 1 1 9 12 8 7 56 2 1 9 19 8 6 48
[Code]...
Code:
struct data { //Here /*! horizontal position */ int x; /*! vertical position */ int y; /*! width */ int w; /
[Code]...
data and then i have an array /*! it contain group_id of each data line*/ int group_id[16]={0,0,0,0,3,3,1,1,1,3,3,2,2,2,2,1}; I never worked with 2D array before. My problem is that i want to create a 2D array of that data for example if i write data[j][i].. It will give me the reference/value of all data lines that belongs to j column, and same with group_id[j][i]. I don't know how i can store these structure vaules in this like 2D array.
I have to enter the Instructor ID and invokes getFees to find the fees of the given instructor. Then it will displays the message that shows either the fees or "No such instructor ID" if not found. the function prototype is
double.getProfessionFees(string); #include <iostream> using namespace std; const int DECLARED_SIZE = 7; int search(const int a[], int number_used, int target); struct InstructorType