Simple c++ program -
could tell me error , why when execute program, random numbers displayed?
#include <iostream> using namespace std; int main() { int total; cout << "please come in number: "; double x1; cin >> x1; total = total + x1; cout << "total: " << total << endl; cout << "please come in number: "; double x2; cin >> x2; total = total + x2; cout << "total: " << total << endl; total = total / 2; cout << "total: " << total << endl; cout << "the average " << total << endl; homecoming 0; }
variable total
not initialized. must initialize first before utilize it, this:
int total = 0;
c++
No comments:
Post a Comment