Hi... I am doing an assignment for average rainfall and i duno whether my coding is correct or not, i need hlp please... thx

#include<iostream.h>
void main()
{
int jan,feb,mar,avg;
char option;

do
{

cout<<" Please enter the amount of rain in January : ";
cin>>jan;
cout<<" Please enter the amount of rain in February : ";
cin>>feb;
cout<<" Please enter the amount of rain in March : ";
cin>>mar;

avg=(jan+feb+mar)/3;

cout<<"\n January |";
for(int j=1;j<=jan;j++)
{
cout<<"*";
}
cout<<"\n February|";
for(int f=1;f<=feb;f++)
{
cout<<"*";
}
cout<<"\n March |";
for(int m=1;m<=mar;m++)
{
cout<<"*";
}
cout<<"\n |____5____10____15____20____25____30____35____40____45____50 \n";




cout<<" Average |";
for(int a=1;a<=avg;a++)
{
cout<<"*";
}
cout<<endl;
system("CLS")
cout<<" Do you wish to continue ? <y/n> \n";
cin>>option;
}while(option=='y'||option=='Y');
cout<<" Please press any key to EXIT \n";
}
#include<iostream.h>
Very old, pre-standard C++ (and thus not correct C++ - get a compiler less than a decade old).

void main()
This has never been correct C++. If your compiler doesn't even warn, throw it away and get a new compiler. This will also mean you'll have to learn about namespace.

avg=(jan+feb+mar)/3;
You are dividing an int by another int, which will give you an int answer (e.g. if jan, feb and mar are all 1, the answer you get will be zero - this is bad). I suggest you don't use int values for this.

system("CLS")
system is very expensive, and this is dangerous (and horribly non-portable) - it surrenders control to an outside program. There are much better ways to do this without the expense or danger.

cout<<" Please press any key to EXIT \n";
That won't actually make it wait for the user to press a key.


Last edited on
Instead of using .h i should use namespace std?
my lecturer wanted us to clear the above prompt after the user enter the y or n... so wad can i use that to clear the above promt?
user need to read and follow instructions right? why wont they wait and enter they key?
Your code should start like this (Try to get a good compiler like wxDevC++ or MinGW Developer Studio 2.0):

1
2
3
4
5
6
#include <iostream>
using namespace std;
int main()
{

}
Topic archived. No new replies allowed.