rain

Discussion in 'C++' started by littlegirl, Mar 29, 2006.

  1. littlegirl

    littlegirl Guest

    girls should not take c++ but can some one hel

    Do not use global variable
    i need to calculate total rainfal
    average rain fal
    and show highest and lowest mont

    i cant seem to get the total or the highest or lowest to display an
    help thank you



    #include <iostream
    #include <string
    using namespace std

    int getActualRain(int j)
    string print_month(int month)
    //char January, February

    int main(


    int i
    float AverageRain[13]
    float ActualRain[13]

    for (i = 1; i < 13; i++

    cout << "Enter Monthly Rainfall for " << print_month(i
    << ": "
    cin >> AverageRain

    double TotalMonths
    monthly
    int total = 0

    for(int currMonth = 0; currMonth < TotalMonths; currMonth++

    total = total + ActualRain[currMonth]



    return 0


    string print_month(int month

    string result
    switch (month

    case 1
    result = "January"
    break
    case 2
    result = "February"
    break
    case 3
    result = "March"
    break
    case 4
    result = "April"
    break
    case 5
    result = "May"
    break
    case 6
    result = "June"
    break
    case 7
    result = "July"
    break
    case 8
    result = "August"
    break
    case 9
    result = "September"
    break
    case 10
    result = "October"
    break
    case 11
    result = "November"
    break
    case 12
    result = "December"
    break
    default
    cout << "Invalid Value!\a"
    break

    return result
     
    littlegirl, Mar 29, 2006
    #1
    1. Advertising

  2. littlegirl

    Jaspreet Guest

    littlegirl wrote:
    > girls should not take c++ but can some one help


    Oh thats why there were hardly any girls by the time I finished my last
    semester. However I would love to have them around. :)

    >
    > Do not use global variables


    Yes they are not cosidered good. One of the methods might accidently
    modify their values.

    > i need to calculate total rainfall
    > average rain fall
    > and show highest and lowest month
    >
    > i cant seem to get the total or the highest or lowest to display any
    > help thank you.
    >
    >
    >
    >
    >
    >
    > #include <iostream>
    > #include <string>
    > using namespace std;
    >
    > int getActualRain(int j);
    > string print_month(int month);
    > //char January, February;
    >
    >
    > int main()
    >
    > {
    > int i;
    > float AverageRain[13];


    Average variable needs to be just 1 variable. Why have an array of 13
    elements ?

    float AverageRain;

    > float ActualRain[13];

    There are 12 months. So declare ActualRain to be of size 12.
    float ActualRain[12];
    >
    >
    > for (i = 1; i < 13; i++)


    always start index from 0.
    for (i = 0; i < 12; i++)

    > {
    > cout << "Enter Monthly Rainfall for " << print_month(i)


    cout << "Enter Monthly Rainfall for " << print_month(i+1)


    > << ": ";
    > cin >> AverageRain;


    cin>>ActualRain;

    > }
    > double TotalMonths,
    > monthly;
    > int total = 0;
    >

    TotalMonths needs to be initialised with value 12.

    > for(int currMonth = 0; currMonth < TotalMonths; currMonth++)
    > {
    > total = total + ActualRain[currMonth];
    >
    > }
    >
    >

    Display total variable.

    cout<<total<<"\n";

    > return 0;
    > }
    >
    > string print_month(int month)
    > {
    > string result;
    > switch (month)
    > {
    > case 1:
    > result = "January";
    > break;
    > case 2:
    > result = "February";
    > break;
    > case 3:
    > result = "March";
    > break;
    > case 4:
    > result = "April";
    > break;
    > case 5:
    > result = "May";
    > break;
    > case 6:
    > result = "June";
    > break;
    > case 7:
    > result = "July";
    > break;
    > case 8:
    > result = "August";
    > break;
    > case 9:
    > result = "September";
    > break;
    > case 10:
    > result = "October";
    > break;
    > case 11:
    > result = "November";
    > break;
    > case 12:
    > result = "December";
    > break;
    > default:
    > cout << "Invalid Value!\a";
    > break;
    > }
    > return result;


    }
     
    Jaspreet, Mar 29, 2006
    #2
    1. Advertising

  3. littlegirl

    Sunil Varma Guest

    littlegirl wrote:
    > girls should not take c++ but can some one help
    >
    > Do not use global variables
    > i need to calculate total rainfall
    > average rain fall
    > and show highest and lowest month
    >
    > i cant seem to get the total or the highest or lowest to display any
    > help thank you.
    >
    >
    >
    >
    >
    >
    > #include <iostream>
    > #include <string>
    > using namespace std;
    >
    > int getActualRain(int j);
    > string print_month(int month);
    > //char January, February;
    >
    >
    > int main()
    >
    > {
    > int i;
    > float AverageRain[13];
    > float ActualRain[13];
    >
    >
    > for (i = 1; i < 13; i++)
    > {
    > cout << "Enter Monthly Rainfall for " << print_month(i)
    > << ": ";
    > cin >> AverageRain;


    ----------------------------------
    Make it
    cin>>AverageRain;
    ----------------------------------

    > }
    > double TotalMonths,
    > monthly;
    > int total = 0;
    >
    > for(int currMonth = 0; currMonth < TotalMonths; currMonth++)
    > {
    > total = total + ActualRain[currMonth];
    >
    > }
    >
    >
    > return 0;
    > }
    >
    > string print_month(int month)
    > {
    > string result;
    > switch (month)
    > {
    > case 1:
    > result = "January";
    > break;
    > case 2:
    > result = "February";
    > break;
    > case 3:
    > result = "March";
    > break;
    > case 4:
    > result = "April";
    > break;
    > case 5:
    > result = "May";
    > break;
    > case 6:
    > result = "June";
    > break;
    > case 7:
    > result = "July";
    > break;
    > case 8:
    > result = "August";
    > break;
    > case 9:
    > result = "September";
    > break;
    > case 10:
    > result = "October";
    > break;
    > case 11:
    > result = "November";
    > break;
    > case 12:
    > result = "December";
    > break;
    > default:
    > cout << "Invalid Value!\a";
    > break;
    > }
    > return result;
     
    Sunil Varma, Mar 29, 2006
    #3

  4. > string print_month(int month)
    > {
    > string result;
    > switch (month)
    > {
    > case 1:
    > result = "January";
    > break;
    > case 2:
    > result = "February";
    > break;
    > case 3:
    > result = "March";
    > break;
    > case 4:
    > result = "April";
    > break;
    > case 5:
    > result = "May";
    > break;
    > case 6:
    > result = "June";
    > break;
    > case 7:
    > result = "July";
    > break;
    > case 8:
    > result = "August";
    > break;
    > case 9:
    > result = "September";
    > break;
    > case 10:
    > result = "October";
    > break;
    > case 11:
    > result = "November";
    > break;
    > case 12:
    > result = "December";
    > break;
    > default:
    > cout << "Invalid Value!\a";
    > break;
    > }
    > return result;



    You can shorten this by creating an array of constant strings and
    return an indexed copy of the contents:

    string print_month(int month) // base index=1 !!
    {
    const char* results[]={
    "January", "Feb", "Mar", "Ap", "M", "Jn",
    "Jl", "A", "S", "O", N", "D"
    };
    return string(results[month-1]);
    }

    Also, this function should be called "get_month_name" instead of
    "print_month", since it doesn't actually print something ;)

    Bye,
    -Gernot
     
    Gernot Frisch, Mar 29, 2006
    #4
  5. littlegirl

    Phlip Guest

    littlegirl wrote:

    > girls should not take c++ but can some one help


    Totally. Girls are smarter than guys, and should lead them to do all the
    stupid jobs, such as cleaning up stables or writing C++ code.

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
     
    Phlip, Mar 29, 2006
    #5
  6. littlegirl

    osmium Guest

    "Gernot Frisch" wrote:

    >> string print_month(int month)
    >> {
    >> string result;
    >> switch (month)
    >> {
    >> case 1:
    >> result = "January";
    >> break;
    >> case 2:
    >> result = "February";
    >> break;
    >> case 3:
    >> result = "March";
    >> break;
    >> case 4:
    >> result = "April";
    >> break;
    >> case 5:
    >> result = "May";
    >> break;
    >> case 6:
    >> result = "June";
    >> break;
    >> case 7:
    >> result = "July";
    >> break;
    >> case 8:
    >> result = "August";
    >> break;
    >> case 9:
    >> result = "September";
    >> break;
    >> case 10:
    >> result = "October";
    >> break;
    >> case 11:
    >> result = "November";
    >> break;
    >> case 12:
    >> result = "December";
    >> break;
    >> default:
    >> cout << "Invalid Value!\a";
    >> break;
    >> }
    >> return result;

    >
    >
    > You can shorten this by creating an array of constant strings and return
    > an indexed copy of the contents:
    >
    > string print_month(int month) // base index=1 !!
    > {
    > const char* results[]={
    > "January", "Feb", "Mar", "Ap", "M", "Jn",
    > "Jl", "A", "S", "O", N", "D"
    > };
    > return string(results[month-1]);
    > }
    >
    > Also, this function should be called "get_month_name" instead of
    > "print_month", since it doesn't actually print something ;)


    I didn't look at her code, but presuming it works ....She had an invalid
    value as a possibility which you seem to ignore. Why do you feel you are
    authorized to change the implicit specification?
     
    osmium, Mar 29, 2006
    #6

  7. >> You can shorten this by creating an array of constant strings and
    >> return
    >> an indexed copy of the contents:

    > I didn't look at her code, but presuming it works ....She had an
    > invalid value as a possibility which you seem to ignore. Why do you
    > feel you are authorized to change the implicit specification?


    I was just pointing out that an array would be shorter/easier to code.
    I assumed she's clever enough to figure out how to perform a range
    test before that.
     
    Gernot Frisch, Mar 30, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike

    rain loop

    Mike, Apr 28, 2010, in forum: C++
    Replies:
    3
    Views:
    717
    Nick Keighley
    Apr 30, 2010
Loading...

Share This Page