Have a question?
Message sent Close

CIS170C Programming Generator Solves for Coin Flip DeVry University

0
0 reviews
  • Description
  • Full Document
Blur-Preview

DeVry University

CIS170C Programming Generator Solves for Coin Flip DeVry University

if (choice == ‘C’) { //Generator solves for coin flip
cout << “How many times do you want to flip the coin: “;
cin >> toss;
for (int i = 0; i < toss; i++) {
if (flipCoin() == 1) { //Determines tails
cout << “flip” << (i + 1) << ” : tails\n”;
}
else { //Determines heads
cout << “flip” << (i + 1) << ” : heads\n”;
}
}
}
else if (choice == ‘D’) { //Generator solves for coin flip
cout << “How many sides does your die have: “;
cin >> numSides;
cout << “How many times do you want to roll the die: “;
cin >> toss;
for (int i = 0; i < toss; i++) {
cout << “roll ” << (i + 1) << ” : ” << rollDice(numSides) << endl;
}
}
else { //Ends program
cout << “Thanks for playing!” << endl;
cout << “Press any key to continue…” << endl;
choice = ‘E’;
}
}
cin.get();
cin.get();
return 0;
}
// flipCoin Function
int flipCoin() {
return 1 + rand() % 2;
}
//rollDice Function
int rollDice(int sides) { //rollDice Function
return 1 + rand() % sides;

Preview

CIS170C Programming Generator Solves for Coin Flip DeVry University

NOTE: Please check the details before purchasing the document.

error: