Calculator (I'm total newbie!)

Started by
15 comments, last by Aardvajk 17 years, 12 months ago
Well, I've never used it but I think cin.get() SHOULD make your program wait for a key before exiting. Code looks okay at first glance.

Easiest way to see if this is the problem IMO is to run a DOS prompt, cd to the directory the executable is in and run it from there, then the screen output will be preserved even if the program is terminating automatically without waiting for a key.

If you are developing for Win32, you could try system("pause"); at the end (you'll need stdlib.h) but this is highly implementation dependant.
Advertisement
I think you should use switch instead of many if/else. Because switch is faster than if/else.

switch(var)
case '+':
....
break;

case '-':
....
break;

case '/':
....
break;

case '*':
....
break;

default:
....
}
DinGY
Yesterday is history.Tomorrow is a mystery. Today is a gift"
you can just use getchar() for C code too

that makes to program wait till you press a key

just put that at the end of your code
Quote:

Originally Posted By Easily Confused

Well, I've never used it but I think cin.get() SHOULD make your program wait for a key before exiting. Code looks okay at first glance.

Easiest way to see if this is the problem IMO is to run a DOS prompt, cd to the directory the executable is in and run it from there, then the screen output will be preserved even if the program is terminating automatically without waiting for a key.

If you are developing for Win32, you could try system("pause"); at the end (you'll need stdlib.h) but this is highly implementation dependant.


Well it works fine I see! so just the pause thing, and Invisal, I'm trying not to change the code completely, but thanks for the advice :-D I'll use it the next time!
I wanna become a good programmer for my game :-)
Quote:Original post by Endar
You can have an if inside an if inside an if inside an if, ad infinitum.

Okay, well not really to infinity, but I don't know the limit. Does anyone know? Does anyone have the C/C++ standard lying around?


There is no limit. The program needs to fit into memory, though.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

That's correct :-D
Hehe!

found out the calculator close problem, it seems that the last time you press enter (at the second number) it activates the next cin.get() :-) so just placed one more and it works! :-D
I wanna become a good programmer for my game :-)
Yeah, actually don't use system("pause") ever. Someone has just pointed out in another thread that if someone malicious puts a program called pause.exe in the same directory as your program, they can do anything they want when your program ends. Hadn't thought of that.

This topic is closed to new replies.

Advertisement