Solved

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

Posted on 2004-10-11
4
196 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

756 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