0
(SOLVED) for_while!! x, sum integers are not defined in this scope, why?
#include <iostream> using namespace std; int main() { do { int x = 0; int numbers = 0; int sum = 0; x++; cin >> numbers; sum = sum + numbers; }while(x<=5); cout << sum; return 0; }
3 Answers
+ 6
fergoka you have defined sum inside do which will be treat as local variable.
Do like this:
int sum = 0;
do {
sum += 5;
} while (x <= 5);
+ 3
You haven't defined x and sum in the in the main function ,they are only defined in the do Loop scope
intialize and define outside do Loop
int x=0;
int numbers;
int sum=0;
+ 1
Uf..how silly I am. Thank you, AJ!
Edit: Thanks Abhay.