Author | Post | |||
Dhaos |
Hi guys hopefully you can help me THE NOOB, heheh thx, the problem is when i compile it in visual c++ it works great but when i take the application out of thedebug folder and put it onto the floppy and run the application it works but when i type a number an hit enter it exits, anyways here the code // Circle.cpp // Circumference of a circle // Programmer: David R. Quigley // 3/28/2006 #include <iostream.h> main() { const float PI = 3.14159f; // Declaring PI as a constant floating number float circumference, radius; // Asks user for radius cout << "What is the radius of the circle? "; cin >> radius; circumference = 2 * PI * radius; // Formula for circumference of a perfect circle. // Output The circumference of the circle cout << "The circle's circumference is "; cout << circumference << '\n'; return 0; } |
|||
28.03.2006 22:30:32 |
|
|||
quangntenemy |
There's no problem with the code. It's just that the program prints the output and then terminates right away. If you want to see the output of the program try running it in command line or put a getchar() before "return 0" Edit: You also need to include stdio.h to use getchar() |
|||
Edited by quangntenemy on 28.03.2006 23:19:08 | ||||
28.03.2006 23:16:41 |
|
|||
unknown user |
or a bit more c++ like #inlcude <iostream> // no .h using namespace std; . . . char a; cin>>a; return 0; } |
|||
30.03.2006 13:45:29 |
|
|||
Blacklotis |
how about system("pause"); its what ive used in the past |
|||
31.03.2006 01:21:11 |
|
|||
BaRa |
Hi Dhaos, Just put this as the last line: cin.get(); cin.get() waits for the user to enter a character before it continues. Greetz BaRa |
|||
Edited by BaRa on 01.04.2006 21:24:11 | ||||
01.04.2006 21:20:40 |
|
|||
mxn |
Quote: system("pause"); that not only makes the program system dependant, its also ugly++! Better use one of the other solutions suggested here. |
|||
02.04.2006 12:26:15 |
|
|||
cyph1e |
Quote from Blacklotis: system("pause"); It's a bad way, read here why: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1042856625&id=1043284385. system("pause") also spawns another process. |
|||
05.04.2006 17:29:00 |
|
|||
beerhunter |
Note that, if you've just read a value using 'cin >> foo', there'll still be a newline in the input buffer, and cin.get() will return immediately. Add a call to cin.ignore(): float radius; cin >> radius; ... cin.ignore(1000, '\n'); cin.get(); |
|||
05.04.2006 22:42:36 |
|