#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    3
    Rep 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.
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,472
    Rep Power
    15
    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.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    3
    Rep Power
    0
    Thanks guys, everything worked out well. Getting the user input into the array was the only part slowing me down.

IMN logo majestic logo threadwatch logo seochat tools logo