C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 13th, 2003, 09:23 PM
TheBlackshinobi TheBlackshinobi is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 3 TheBlackshinobi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old April 13th, 2003, 11:19 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level)infamous41md User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
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.

Reply With Quote
  #3  
Old April 14th, 2003, 01:12 AM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,365 7stud User rank is Private First Class (20 - 50 Reputation Level)7stud User rank is Private First Class (20 - 50 Reputation Level) 
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.

Reply With Quote
  #4  
Old April 17th, 2003, 09:57 AM
TheBlackshinobi TheBlackshinobi is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 3 TheBlackshinobi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > need help with array homework

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap