473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

rain

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

Mar 29 '06 #1
6 1396

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;


}

Mar 29 '06 #2

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;


Mar 29 '06 #3
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
Mar 29 '06 #4
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!!!
Mar 29 '06 #5
"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?
Mar 29 '06 #6
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.
Mar 30 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ilik | last post by:
Hi all I'm trying to create a summery table of rain data that holds a record for every 0.1mm of rain in the following format: Station Name, Time, Value A, 2002-12-03 14:44:41.000, 0.1 A,...
9
by: Profetas | last post by:
I have to do a program that determine the biggest number in the month I have to use enum so I was wondering can I declare an array of a type like #include <stdio.h>
7
by: Rain | last post by:
Hello Gurus! I really need this one to finish a module in my thesis. PLease please help me. I need a double buffer class so i can call it and use it anytime i want, the problem is everything ive...
6
by: c19h28o2 | last post by:
Hi, I'm learning to use pointers with multidemensional arrays so please bear with me! Here is the problem which is from c primer plus Ch10 Programming excercise 1 Modify the rain program...
14
Dököll
by: Dököll | last post by:
Hey VB Gang! I attempted to send this previously but failed. behold the introduction of a newbie :-) Anyway, I am hoping t find a shortcut to fixing a problem. Modifying a text reader...
21
Dököll
by: Dököll | last post by:
Greetings Again, All! I know a bit more of the back end of things than front. Every now and then I use wildcard to retrieve data via sql advantage, oracle, and of course, our beloved MS Access...
9
by: Joe Fawcett | last post by:
Dear All Can anyone explain why on some machines, when I choose to add a new item to a web site in VS 2008, I get the traditional dialogue that shows the checkbox for choose a master page and on...
2
by: Canye | last post by:
I have a very long list of codes that i was advised to put in a module but don't know where to start from. Also i have a botton in my software that i what to use to be adding tabs when running my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.