|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Hi,
Do you know how to get input from the user? cin>>number_a; cin>>number_b; cin>>number_c; An array is essentially the same thing as number_a, number_b, and number_c. The line: int number[3]; declares three variables of type int: number[0], number[1], and number[2]. 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: Code:
int number[1000];
for(int i=0; i<1000; i++)
{
cout<<"Enter data "<<i<<": ";
cin number[i];
}
Isn't that a lot easier? Last edited by 7stud : April 14th, 2003 at 01:24 AM. |
|
#4
|
|||
|
|||
|
Thanks guys, everything worked out well. Getting the user input into the array was the only part slowing me down.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > need help with array homework |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|