CIS170C WEEK 4 LAB.docx

30 July, 2024 | 1 Min Read

Week 4 Lab

CIS170c

DeVry University

#include < iostream >

#include < string > #include < ctime > using namespace std;

//function protoype string flipCoin(); int rollDice(int sides);

int main()

{

char choice = **;

//seed the random number generator time_t time(0); srand(seed);

cout << “welcome to our coin toss and dice rolling program'; <<end1; While(choice != ‘E’) ;

{

cout << “what would you like to choose flip coin(C), roll a dice (D), or exit (E)"; cin » choice;

if (choice == ‘C’ || choice == ‘c’)

{

cout << “how many times do you wan to flip a coin: “; cin » numtoss;

for (int i = 0; i < numtoss; i++)

{ cout << “flip " << i << " is " << flipcoin() << end1; }

}

}

if (choice == ‘D’ || choice == ’d')

{

}

else

{

cout << “Thanks for playing!";

}

}

system(“pause”) ; return 0; string flipCoin()

{ int toss = 1 + rand() % 2; if (toss == 1)

{

return “heads”;

}

else

{ return “tails”;

}

}

Related posts