Your mistake is that you didn’t put a pause at the end of the main().
To fix it you can either put at the end of main command system(“pause”); or you could do it this way
char c; std::cin >> c;
return;
This way it will wait for character input and then if you want to terminate your application when you input ‘=’
you can write :
if (c=='=') return;
Simple 🙂
If you want your calculator to do multiple calculations until you insert that ‘=’ sign. You can do it this way :
int main()
{
char c;
while(c!='N'){
//YOUR CODE GOES HERE AND IT WILL BE REPEATED UNTIL YOU INSERT N at the end
std::cout << "\n Do one more calculation ? (Y/N) : ";
std::cin >> c;
}
system("pause");
return 0;
}
C:
while(c!='N'){
//YOUR CODE GOES HERE AND IT WILL BE REPEATED UNTIL YOU INSERT N at the end
//Doing it this way, if you type N it will terminate, if you type any other character it will do the loop.
printf(" Do one more calculation ? (Y/N) : ");
scanf("%c", &c);
}
5
solved Multi-functional math calculator in C