Tuesday, July 28, 2009

I need some help with c++?

im using a website to learn c++ and im trying to use this program but every time i run it it goes fine till the end. when its suposed to show the last output it shuts off to fast for me to see it. why doesnt it work? i even tried coping it and pasting it into the compiler and it didn't work. im using the dev-c++ compiler.





#include %26lt;iostream%26gt;





using namespace std;





int main(){








int a;





cout %26lt;%26lt; "What time of day is it?\n";


cout %26lt;%26lt; "1) Morning\n";


cout %26lt;%26lt; "2) Afternoon\n";


cout %26lt;%26lt; "3) Evening\n";


cout %26lt;%26lt; "Enter a choice: ";


cin %26gt;%26gt; a;





switch (a){





case 1:


cout %26lt;%26lt; "Good Morning!";


break;


case 2:


cout %26lt;%26lt; "Good Afternoon!";


break;


case 3:


cout %26lt;%26lt; "Good Evening!";


break;





default:


cout %26lt;%26lt; "Not a valid entry...";


break;





}








}

I need some help with c++?
You are probably on a Windows system. When you click your program in a folder, a DOS shell appears and runs the program. As soon as it is done, it will disappear.





You have two choices.





1. On the last line of the program, add the line cin.get(). That will keep the program up waiting for input from the user. Use the return key.





2. Open a DOS shell and run the program at the command line. You will have to cd into the directory where the program is located to run it.





Hope this helps.
Reply:I use MS Visual Studio 2005. You can get a free version online from Microsoft but I had same problem.





If you look, There's build to compile it. There's also a run without compile. Your program might have the same thing.





It should be under your menu somewhere, I clicked around till I found what I needed.


No comments:

Post a Comment