Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > rain

Reply
 
 
littlegirl
Guest
Posts: n/a
 
      03-29-2006
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

 
Reply With Quote
 
 
 
 
Jaspreet
Guest
Posts: n/a
 
      03-29-2006

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[i];

> }
> 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;


}

 
Reply With Quote
 
 
 
 
Sunil Varma
Guest
Posts: n/a
 
      03-29-2006

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[i];
----------------------------------

> }
> 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;


 
Reply With Quote
 
Gernot Frisch
Guest
Posts: n/a
 
      03-29-2006

> 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


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-29-2006
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!!!


 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      03-29-2006
"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?


 
Reply With Quote
 
Gernot Frisch
Guest
Posts: n/a
 
      03-30-2006

>> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
persistant light rain neville Computer Support 16 04-17-2005 03:40 PM
protect camera for shooting in the rain Daniel Digital Photography 8 04-07-2004 09:14 PM
TheDigitalReview: RAIN MAN: SPECIAL EDITION - DVD REVIEW Mike McGee DVD Video 0 02-03-2004 11:52 AM
New Releases: Ed Wood, Rain Main & Anime: Updated complete R1 DVD DB & info lists Doug MacLean DVD Video 0 11-11-2003 05:37 AM
Black Rain: Special Edition?? alex crouvier DVD Video 4 10-21-2003 11:02 PM



Advertisments