The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
need help with array homework
Discuss need help with array homework in the C Programming forum on Dev Shed. need help with array homework C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 13th, 2003, 09:23 PM
|
|
Junior Member
|
|
Join Date: Aug 2002
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
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
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 20 m 28 sec
Reputation Power: 14
|
|
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.
|

April 17th, 2003, 09:57 AM
|
|
Junior Member
|
|
Join Date: Aug 2002
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thanks guys, everything worked out well. Getting the user input into the array was the only part slowing me down.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|