Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do i get the program to loop around if they press enter

Posted on 2004-10-11
4
Medium Priority
?
200 Views
Last Modified: 2010-04-01
in the switch statement where it says please roll again i want the user to be able to press enter and then the dice to roll again


      cout << "Welcome to CRAPS\n\n"  <<  endl;
      
      cout << "Please pleace your bet" << endl;      
      cin  >> Bet;


while(TotalMoney >= 0){




cout << "Point " << Point;      
cout << "Counter " << Counter;
srand(time(0));
Dice1 = 1 + rand() % 6;
Dice2 = 1 + rand() % 6;




SumOfDice = Dice1 + Dice2;
cout << "You rolled a sum of " << SumOfDice << endl;




      

Counter = ++Counter;

case 2:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
      
break;
      }
0
Comment
Question by:tedschnieders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
aravindtj earned 2000 total points
ID: 12278509
Put the following statments before the end of while loop.

flush(stdin);
while (getch() == '\n');

this will loop forever while you press enter key.

all the best.
0
 
LVL 12

Expert Comment

by:stefan73
ID: 12278644
Hi tedschnieders,
Don't mix C stdio with C++ IO. Use either.

Cheers!

Stefan
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12278830
Include <string> and use getline to read into a junk string.
0
 

Author Comment

by:tedschnieders
ID: 12280316
i have to do this is an assignment and i have been worken on it forever.........it sucks

i dont know programming enough could someone compile this and and show me how to finish this

if they roll there point it keeps looping til they when or lose but i want them to have to press enter to get the dice to show up again
hopefully you get what i am talken about ccause im not sure if i know

thank you much
ted

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;

int main(){
int Dice1        = 0;
int Dice2        = 0;
float Bet        = 0;
int Point        = 0;
int SumOfDice    = 0;
float TotalMoney = 1000;
int Counter = 0;

      cout << "Welcome to CRAPS\n\n"  <<  endl;
      
      cout << "Please pleace your bet" << endl;      
      cin  >> Bet;

srand(time(0));

while(TotalMoney > 0){




cout << "Point " << Point;      
cout << "Counter " << Counter;

Dice1 = 1 + rand() % 6;
Dice2 = 1 + rand() % 6;

SumOfDice = Dice1 + Dice2;
cout << "You rolled a sum of " << SumOfDice << endl;

Counter = ++Counter;




      
switch(Dice1){

case 1:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*          *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 2:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*            *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 3:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 4:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 5:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*     *   *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 6:
      cout <<      "\n***********\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "***********\n";
break;
}      
switch(Dice2){

case 1:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*          *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 2:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*            *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 3:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 4:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 5:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*     *   *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 6:
      cout <<      "***********\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "***********\n";
break;
      }
                  
switch(SumOfDice){

case 2:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
      

break;
      }
case 3:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }

case 4:      
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;      
      }
      else if(Counter > 1 && Point == 4){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 5:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;      
      }
      else if(Counter > 1 && Point == 5){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 6:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;
      }      
      else if(Counter > 1 && Point == 6){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 7:
      if(Counter == 1 && Point == 0){
      cout << "WINNER!!! You rolled a " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1 && Point >= 1) {
      cout << "SORRY!! You did not win ......:(PLEASE  AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 8:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;
      }
      else if(Counter > 1 && Point == 8){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
}
case 9:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;
      }
      else if(Counter > 1 && Point == 9){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;      
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 10:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;      
      }
      else if(Counter > 1 && Point == 10){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 11:
      if(Counter == 1){
      cout << "WINNER!!! You rolled a " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;      
      }
      else{
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }
case 12:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;

break;
}      
      return 0;


}    
      }
            }
             
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question