So, I have done a basic calculator program for college, but when you execute the calculation it prints the answer and the program closes. I have tried system("pause") but it still doesn't change anything and I do have iostream and all the #includes needed for it.
Some quick research showed me that "stdio.h" was the header file used for the "system("pause");".
Your code above does not show the use of "system", so I am wondering if you are missing a header file or if your usage is wrong? A lot of programs I white include "Windows.h" and I have not had any problem using a system call.
Quite often I will include "conio.h" and use this code at the end of the program while working with the program and than remove it when I am finished.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//#define RELEASE // First line in the file. Uncomment when testing is finished.
#ifndef RELEASE
#include <conio.h>
#endif
// Program here
#ifndef RELEASE
std::cout << "\n\n\n\n Press anykey to continue";
_getch();
#endif
return 0;
} // End of main
I use "_getch()" because my compiler complains about "getch()".
A better way to avoid using "system("pause");" would be to wrap lines 12 - 45 in a do/while loop with the while condition as } while (cont); with "cont" defined as bool cont{ true };. Then in the case statements add:
1 2 3 4
case'q':
case'Q':
cont = false;
break;
Adjust line 12 to add 'q' to quit nd you will not have to worry about a pause at the end of the program.
Sorry. I did say it was quick not in-depth I was rushed at the time and did not go as far as I would normally do. Also I have written programs which include "Windows.h" and have had no problem using "system"
Sorry. I did say it was quick not in-depth I was rushed at the time and did not go as far as I would normally do.
I'm kinda curious as to which source you found that told you that stdio.h - a C header file, not a C++ one - was the one you needed for system. Whatever source that was, I'd advise not trusting it in future, and find a more trustworthy source.
I have written programs which include "Windows.h" and have had no problem using "system"
You're aware that header files include other header files, right?
I do not remember where I did the search from. It was either Google or on this site. Either way I just checked the first link or two that came up. Where ever it was I felt that it was good information. I see now that I need to be more careful in the future.
Yes, I do know that a header file can include others. I actually wrote a header file that includes another that includes another. And before you say it I do know that "Windows.h" is something I should not be using, but it like "conio.h" they work with some of the functions I use,, but they are mostly for my use not everyone else. At least until I can find something better.