Sunday, 15 June 2014

c++ - The variable answer is being used without being initialized? -



c++ - The variable answer is being used without being initialized? -

any help? when set 2 numbers in, says reply not beingness initialized...?

#include <iostream> using namespace std; int main() { int num; int num2; int working; int answer; int uchoice; int work( int one, int two, int todo ); cout << "welcome basic mini-calculator!" << endl; { cout << endl << "what want do?" << endl; cout << "1) add" << endl; cout << "2) subtract" << endl; cout << "3) multiply" << endl; cout << "4) divide" << endl; cout << endl << "waiting input... (enter number): "; cin >> uchoice; cout << endl; } while( uchoice != 1 && uchoice != 2 && uchoice != 3 && uchoice != 4 ); switch ( uchoice ) { case 1: cout << endl << "you chose addition." << endl; cout << "enter number: "; cin >> num; cout << "enter number: "; cin >> num2; working = num + num2; cout << "your reply is: " << answer; break; case 2: cout << endl << "you chose subtraction." << endl; cout << "enter number: "; cin >> num; cout << "enter number: "; cin >> num2; working = num - num2; cout << "your reply is: " << answer; break; case 3: cout << endl << "you chose multiplication." << endl; cout << "enter number: "; cin >> num; cout << "enter number: "; cin >> num2; working = num * num2; cout << "your reply is: " << answer; break; case 4: cout << endl << "you chose division." << endl; cout << "enter number: "; cin >> num; cout << "enter number: "; cin >> num2; working = num / num2; cout << "your reply is: " << answer; break; homecoming 0; } }

it that. declare answer:

int answer;

then utilize many times without initializing or assigning values it:

cout << "your reply is: " << answer;

c++

No comments:

Post a Comment