I know I must be missing something, but in a while statement how does the variable hold the data, when it finishes the first pass and goes into the second pass?
{
int num1 = 0 ; int num2 = 0; int num3 = 0; while (num1 < 10) {cout << 'enter your first number: '; cin >> num1; cout << 'Enter your second number: '; cin >> num2; num1 = num1 + num2 ; cout << 'Number 1 is now: ' << num1 <<endl; cout << 'Enter Number 3: ' ; cin >> num3; num1 = num1 + num3; cout << 'Number 1 is now: ' << num1 << endl; num1++; };
In this code. The Variable doesn’t hold the data. I’m not sure what I’m doing wrong!
Is num1 the variable you’re having trouble with? This line:
is setting num1 to the value input by the user. So the value calculated for it in the previous run through the loop is being overwritten each time by the new input.