What is wrong with my C++ code?
Posted on 2009-04-16
I am just learning C++ and have had to write a program calculating average rainfall. From everything I can tell, I did everything right, but I still get errors when I try to compile.
I am using Micrsoft Visual C++ 2008 Express and the build log is attached. Here is the source code:
//A program to calculate average rainfall
//for a period of three months.
using namespace std;
int main ()
char month1, month2, month3; //To hold the name of the month
double inches1, inches2, inches3; //To hold the rainfall total for month
double average; //To hold the average
//Get the names of the three months used in the calculation
cout << "This program will calculate the average rainfall, in inches, for three months.\n";
cout << "Enter the names of the three months you want to calculate the average rainfall\n";
cout << "for, seperated by a space. (i.e. March April May):";
cin >> month1 >> month2 >> month3;
//Get the amount of rainfall, in inches, for each month.
cout << "What was the total rainfall, in inches, for the month of" << month1 << "?/n";
cin >> inches1;
cout << "What was the total rainfall, in inches, for the month of" << month2 << "?/n";
cin >> inches2;
cout << "What was the total rainfall, in inches, for the month of" <<month3 << "?/n";
cin >> inches3;
//Calculate the average rainfall for the three months.
average = (inches1 + inches2 + inches3) / 3.0;
//Display the average rainfall
cout >> "The average rainfall for << month1 << "," << month2 << ;
cout >> ", and" << month3 << "is" << average << "inches./n";