Getting this error: (68): error C2065: 'programend' : undeclared identifier
(Off-topic note: I know that using using namespace std is bad practice, but I didn’t feel like typing std:: in front of everything. I will if that’s what’s causing the error, however.)
Here’s the code:
#include <iostream>
using namespace std;
int main(void) {
do{
system("title Mini-Calc");
cout << "Hello World! Welcome to Dustin's C++ Calculator!" << endl;
cout << "To get started, enter a number:" << endl;
int operation;
double num1, num2, answer;
cin >> num1;
cout << "Now enter another number:" << endl;
cin >> num2;
cout << "Please type the corrresponding number for the operation desired, and press enter." << endl;
cout << "1 = +, 2 = -, 3 = x, 4 = /" << endl;
cin >> operation;
switch(operation) {
case 1:
answer=num1+num2;
break;
case 2:
answer=num1-num2;
break;
case 3:
answer=num1*num2;
break;
case 4:
answer=num1/num2;
break;
}
cout << "The answer is: " << endl;
cout << answer << endl;
bool programend;
cout << "Would you like to end the program? (y for yes, n for no)" << endl;
cin >> programend;
switch(programend) {
case 'y':
programend=true;
break;
case 'n':
programend=false;
break;
case 'Y':
programend=true;
break;
case 'N':
programend=false;
break;
}
} while (programend==false);
return 0;
}
if you take out the do…while contents, you’ll see that
programendis not declared in the right scope:It should be declared between the
mainand thedoto be available.