April 13th, 2003, 09:23 PM
need help with array homework
I was wondering if someone could help me. I have an assignment for one of my classes and I am having trouble entering numbers into an array.
The objective is to enter the temperatures for one month and get some results. I have to have 28,29,30, or 31 data items depending on the month.
The Function prototypes that I must use are:
int read_temps(int temps);
int hot_days(int n, int temps);
void print_temps(int n, int temps, int hot);
Basically the part that I am having a problem with is having the list of 30 or so numbers entered into the array. Once I get that I will be able to tell the average temperature and how many days were hotter than 32 degrees.
Any help would be greatly appreciated.
April 13th, 2003, 11:19 PM
what exactly are u having a problem with? do u understand what an array is? And how to input values from the user? perhaps u could create a loop that took input from the user and stored it into the array, something along these lines:
for(int x=0; x<= 30;x++)
cout << "\nenter temp: ";
cin >> array[x];
-or course u will need more than that, something that determines how many days are in the month before u enter the loop... but that i will leave to u
Last edited by infamous41md; April 13th, 2003 at 11:21 PM.
April 14th, 2003, 01:12 AM
Do you know how to get input from the user?
An array is essentially the same thing as number_a, number_b, and number_c. The line:
declares three variables of type int: number, number, and number. Why are arrays useful? What if you had 1,000 numbers to read in from the user. Without arrays, you would have to input the numbers like above, which would require you to type 1,000 cin statements. With arrays you can do this:
Isn't that a lot easier?
for(int i=0; i<1000; i++)
cout<<"Enter data "<<i<<": ";
Last edited by 7stud; April 14th, 2003 at 01:24 AM.
April 17th, 2003, 09:57 AM
Thanks guys, everything worked out well. Getting the user input into the array was the only part slowing me down.