This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hello all, So I recently started learning c for school, and I've written this program to try and average three months of rainfall. My problem is stemming from the fact that with this variation of the code i get this error: "binary '/': 'std::basic_string<char,std::char_traits<char>,std::allocator <char>>' does not define this operator or a conversion to a type acceptable to the predefined operator" which makes me think that maybe i can't do math with the string operator? Not sure how to fix this. When i try it without the "/" and just the addition of the rainfall numbers, it doesnt add them and just stack them together so instead of 1 2 3 =6 it goes 1 2 3 = 123. Any help would be much appreciated.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string month1;
string month2;
string month3;
string total;
string rainfall1;
string rainfall2;
string rainfall3;
cout << "This program calculates average rainfall in inches from three different months. \n";
cout << "First month: ";
cin.sync();
getline(cin, month1);
cout << "Second month:";
cin.sync();
getline(cin, month2);
cout << "Third month:";
cin.sync();
getline(cin, month3);
cout << "Rainfall for first month: ";
cin.sync();
getline(cin, rainfall1);
cout << "Rainfall for second month:";
cin.sync();
getline(cin, rainfall2);
cout << "Rainfall for the third month: ";
cin.sync();
getline(cin, rainfall3);
total = (rainfall1 rainfall2 rainfall3) / 3;
cout << "Average monthly rainfall for " << month1 << ", " << month2 << ", and " << month3;
cout << " is " << total << " inches\n";
return 0;
}
Subreddit
Post Details
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...