here is my code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string month1, month2, month3;
double rain1, rain2, rain3, avg;
cout << "Enter the first month: " << month1 << "." << endl;
cin >> month1;
cout << "Enter the first month's rainfall:" << rain1 << "."<< endl;
cin >> rain1;
cout << "Enter the second month: " << month2 << "." << endl;
cin >> month2;
cout << "Enter the second month's rainfall:" << rain2 << "." << endl;
cin >> rain2;
cout << "Enter the third month: " << month3 << "." << endl;
cin >> month3;
cout << "Enter the third month's rainfall:" << rain3 << "." << endl;
cin >> rain3;
avg = (rain1 + rain2 + rain3) / 3;
cout << "The average rainfall for " << month1 << ", " << month2 << ", and " << month3;
cout << " is " << avg << " inches."<< endl;
system ("pause");
return 0;
}
//any help with this error? I have initialized it in the beginning
Last edited on
ok i have a problem setting setprecision(2) to the value avg?? it tells me that the identifier is undefined!
For example in this statement
cout << "Enter the first month's rainfall:" << rain1 << "."<< endl;
you output rain1 that was not initialized.
Write instead
cout << "Enter the first month's rainfall: ";
And change other similar statements the same way.
Last edited on