For all advanced programmers!

Started by
18 comments, last by ProPuke 19 years, 5 months ago
Please Help!! im new at programming therefore im new at C++. So i bought a book which is working great except for this problem. U see i bought the Beginning C++ Game Programming book by Michael Dawson. And im using the Dev-C++ software that came with it. i was working on one of the excercises in the book and when i compiled and ran the program it worked fine. But this was an excercise that i was supposed to hit enter to have the program stay stuff back.And i press enter and the program runs so quickly that it brings me back to my code. Im on page 45 doing the menu chooser program if anyone has the book. He is using Microsoft Visual Studio and i was wondering if maybe instead i should be using that instead of Dev C++. Anyway heres the code im working on. // Menu Chooser // Demonstrates the switch statement #include <iostream> using namespace std; int main() { cout << "Difficulty Levelsn\n\n"; cout << "1 - Easy\n"; cout << "2 - Normal\n"; cout << "3 - Hard\n"; int choice; cout << "Choice: "; cin >> choice; switch (choice) { case 1: cout << "You picked Easy.\n"; break; case 2: cout << "You picked Normal.\n"; break; case 3: cout << "You picked Hard.\n"; break; default: cout << "You made an illegal choice.\n"; } return 0; } if u could answer my questions that would be great
Advertisement
Add a system("PAUSE"); call before return 0.
im really new at this so if you could give me the exact way to write it in my source file so i can practice with it that would be great
// removed system("PAUSE"); return 0;


It's simply a system call that waits (or "pauses") until you press "any key." Otherwise the code will return before you have a chance to see it.
Quote:Original post by ontheheap
Add a system("PAUSE"); call before return 0.

or int x;
cin>>x;
before return 0;
-----------------------------------Panic and anxiety Disorder HQ
well dev-c++ doesn't pause when it hits the end of a console app. As ontheheap said system("PAUSE"); is a standard way of inserting a pause in a program. But first I recommend you find an ide you are fully comfortable with. And no, I don't recommend visual studio.
MinGW Developer Studio, however is an excellent ide & I completely recommend it. I found dev-c++ abit of a mess to work with & generally unfriendly.
Give MinGW studio a try & see what you think. It's the best ide I've used & ofcourse is free & uses the g++ compiler (good stuff) unlike microsofts pricey alternative with it's non standard(we'll make our own rules up) compiler.
It's just a neater, cleaner alternative to something else like dev-c++. Thought I'd share the advice
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
Yea, that works too. (And is probably better practice since it's system independent).
I second MinGW DS. Great IDE.
Or if you run the program from the dos prompt, it won't dissapear when it finishes running.
You mean cmd.exe, right? Unless he's using 95/98 there is no DOS prompt.

This topic is closed to new replies.

Advertisement