Logic?

This is a discussion on Logic? within the C++ Programming forums, part of the General Programming Boards category; I am a student trying to complete some homework. The program is supposed to demonstrate the use of an array. ...

  1. #1
    Kurious
    Guest

    Logic?

    I am a student trying to complete some homework.
    The program is supposed to demonstrate the use of an array.
    The program is supposed to input the rainfall amounts for twelve months. It is then supposed to calulate the total amount, the average, and then tell the months with the highest and lowest amounts. I'm not sure what way I should use to compare the amounts to find the highest and lowest amounts.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>I'm not sure what way I should use to compare the amounts to find the highest and lowest amounts.
    Create 2 variables to hold the 2 extreme numbers, highest and lowest. As you read in the new data, compare each one to the highest/lowest variables, if they are more extreme, update the highest/lowest variable accordingly.

    Use < and > within an if statement to compare values.

    Post some code when you have troubles.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    *sniff sniff* I smell homework AGAIN

    Well try this:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int waterfall_rain_amount[12];
    
    int main(void)
    {
    int a;
    int b;
    
    for(a=0;a<=11;a=a+1)
    {
    cin >> water_fall_rain_amount[a];
    }
    
    for(a=0;a<=11;a=a+1)
    {
    b+=water_fall_rain_amount[a];
    }
    
    cout << "Amount of rain is" << b/12 << endl;
    
    
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    use a var like int temp[] to store the needed stuff
    then u can check the temps for lowest-highest values?!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Logic
    By LordBronz in forum C++ Programming
    Replies: 6
    Last Post: 05-23-2006, 06:41 PM
  3. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 11:58 PM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 09:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21