![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
It ain't making this prog stall!!?
#include <iostream>
using namespace std;
int main() {
double ctemp, ftemp;
cout << "Input Celsius temp and press ENTER:\n >> ";
cin >> ctemp;
ftemp = (ctemp * 1.8) + 32;
cout << "Farenheit temp is: " << ftemp;
cin.get();
return 0;
}
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#12 |
|
Programmer
Join Date: Jun 2005
Location: Maryland, USA
Posts: 59
Rep Power: 4
![]() |
I have always got my copies from my employer, so have never had to pay for it. I believe you can get the non-optimized, non-enterprise version for around $50 US while an enterprise, fully optimized version may go for 10-20 times that. The debugger in the IDE is the best I have used and I am generally quite happy with the rest of the IDE. It compiles programs faster than any other compiler I have used and the resulting binaries execute at least as fast as the others I have used, though from what I read, if you have Intel hardware, you can't beat Intel's compiler. I would stick with DevC until you feel you want to do this for a living, in which case you can probably get VC from your employer.
__________________
Free code: http://sol-biotech.com/code/. It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it. --Mitakeet The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --George Bernard Shaw |
|
|
|
|
|
#13 |
|
Programmer
Join Date: Jun 2005
Location: Maryland, USA
Posts: 59
Rep Power: 4
![]() |
You have left over 'stuff' in the stream (linefeed, most likely), try this:
#include <iostream>
using namespace std;
int main() {
double ctemp, ftemp;
cout << "Input Celsius temp and press ENTER:\n >> ";
cin >> ctemp;
ftemp = (ctemp * 1.8) + 32;
cout << "Farenheit temp is: " << ftemp;
cin.synch();
cin.get();
return 0;
}
__________________
Free code: http://sol-biotech.com/code/. It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it. --Mitakeet The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --George Bernard Shaw |
|
|
|
|
|
#14 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
cin.synch();
returning error - no matching function... why does even the most simple thing have to be confusin!!i came up with a sloppy but addequate for the time being. cin >> ctemp cout << "blah blah yaaa: " << ctemp; cin >> ctemp
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#15 |
|
Programmer
Join Date: Jun 2005
Location: Maryland, USA
Posts: 59
Rep Power: 4
![]() |
Maybe it is sync(). google on 'man cin' and you will probably find all the details you need. Google is your best friend, even when you have been doing this professionally for a decade or longer.
__________________
Free code: http://sol-biotech.com/code/. It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it. --Mitakeet The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --George Bernard Shaw |
|
|
|
|
|
#16 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
lol, ok then mate, i if i can't find it, i'll pop back .
![]()
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#17 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
It is .sync (). As far as compilers go, why don't you download the MS VC++ 2005 beta? It's free, as well, and the debugger's a little better. Keep the Dev-C++. I have both, as well as Borland. With the MS compiler you have to be careful and avoid the .NET stuff (a lot of the default project setup assumes .NET) unless you're just wanting to learn that also. Let me suggest you take time out to read some documentation. It'll keep you from popping in every 5 minutes to ask silly questions. As far as adding the "cin.get ()" to keep the window open, let me explain why that is. If you stop to think about it, you start programs and they run until they're done, then they close. Sometimes they're not "done" until you click a button or the big 'X' or something, but that's just a detail. For your console apps you make it a keystroke to indicate "done" by using cin.get () or similar. If you run your program from the CLI, the window is there when you type the command (your program name), so it remains there when the program exits. In those cases, you won't need a keystroke or click to "hold it open".
EDIT: I just noticed I have become a "hobbyist programmer" after 35 years of programming the little beasties. LOL!
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Last edited by DaWei; Jun 16th, 2005 at 2:21 PM. |
|
|
|
|
|
#18 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
I know why to use cin.get() what i was saying is cin.get() don't work!! in that example! And i am currently going throught doc's. And book's
![]()
__________________
while me is alive: make(life,simple) |
|
|
|
|
|
#19 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
SaturN use getch();
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#20 |
|
Programmer
Join Date: Jun 2005
Location: Maryland, USA
Posts: 59
Rep Power: 4
![]() |
cin.get() grabs one character that is on the stream, blocking if none are available. Since you used cin << to get ftemp, you had to signal the IO handler that you were done entering data (you can use non-blocking IO, but I have never had cause to figure that out). Thus, the linefeed remaining from when you hit enter is still on the stream, patiently waiting to be read so when you use the cin.get() it grabs that linefeed and promptly returns. cin.sync() flushes any pending bytes on the stream leaving it empty, therefore cin.get() blocks until you hit a return. Basically all streams are like that, though at a higher level some IO functions/methods may anticipate what you are trying to do and presume you don't really care about the linefeed and block anyway.
__________________
Free code: http://sol-biotech.com/code/. It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it. --Mitakeet The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --George Bernard Shaw |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|