Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: C++ problem  (Read 3929 times)

0 Members and 1 Guest are viewing this topic.

bil

  • Guest
C++ problem
« on: October 29, 2005, 08:19:12 AM »
alrite im kinda new to C++ and im starting to write small games and when i made my menu script it started good where you had to enter the number to which level of difficulty you want then when u put in the number and hit enter it runs through the rest of the script super fast and exits the screen so can i get some help here heres the script



Code: [Select]

// Menu Chooser
// Demonstrates the switch statement

#include <iostream>
using namespace std;

int main()
{
     cout << "Difficulty Levels\n\n";
     cout << "1 - Easy\n";
     cout << "2 - Normal\n";
     cout << "3 - Hard\n\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;
}
Code: [Select]


ok this is it so far but then i thought it would work if i did this

Code: [Select]

// Menu Chooser
// Demonstrates the switch statement

#include <iostream>
using namespace std;

int main()
{
     cout << "Difficulty Levels\n\n";
     cout << "1 - Easy\n";
     cout << "2 - Normal\n";
     cout << "3 - Hard\n\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";
     }
   std::cout << "press the enter key to exit";
   std::cin.ignore(std::cin.rdbuf()->in_avail() +1);
   return 0;
}
Code: [Select]

but it didnt so does anyone know how to stop this thanks
« Last Edit: October 29, 2005, 08:19:39 AM by bil »

Raptor

  • Guest
Re: C++ problem
« Reply #1 on: October 29, 2005, 09:50:46 AM »
Did you try adding

system("PAUSE")
return 0;

At the end?

bil

  • Guest
Re: C++ problem
« Reply #2 on: October 29, 2005, 10:01:57 AM »
when i try that i get a error here


Code: [Select]
return 0;
Code: [Select]

« Last Edit: October 29, 2005, 10:02:39 AM by bil »

Raptor

  • Guest
Re: C++ problem
« Reply #3 on: October 29, 2005, 06:03:29 PM »
My mistake;

system("PAUSE");
return 0;  

Not  

system("PAUSE")  
return 0;  

Note the additional " ; " behind the pause line.

bil

  • Guest
Re: C++ problem
« Reply #4 on: October 30, 2005, 06:04:18 AM »
IT WORKS

thanks man

Raptor

  • Guest
Re: C++ problem
« Reply #5 on: October 30, 2005, 02:59:55 PM »
No problem, Bil.