- 4
NEED HELP FROM EXPERT! Please put comment on every line of my code. Like why we use this code in this line. For my report.Please
NEED HELP FROM EXPERT 😣
2 odpowiedzi
+ 1
This isn't java as your tag suggests.
0
#include <iostream>
#include <array>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
cout <<"======THE TURTLE RACE======"<<endl;
const int numberOfTurtles = 4;
array<string,4> turtle;
srand(time(NULL));
cout << "PLACE YOUR BET HERE!";
cout << "\n\nEnter your name on your turtle!\n\n";
for(int i = 0; i < 4; i++){
cin >> turtle[i];
}
int winner;
// here will chose the winner
winner = rand() % numberOfTurtles;
int secondPlace;
int thirdPlace;
int fourthPlace;
bool foundSecond = false;
bool foundThird = false;
bool foundFourth = false;
// here we get the second place
while(!foundSecond) {
secondPlace = rand() % numberOfTurtles;
if(secondPlace != winner)
foundSecond = true;
}
// here we get the third place
while(!foundThird ) {
thirdPlace = rand() % numberOfTurtles;
if(thirdPlace != secondPlace && thirdPlace != winner)
foundThird = true;
}
// here we get the fourth place
while(!foundFourth ) {
fourthPlace = rand() % numberOfTurtles;
if( fourthPlace != secondPlace && fourthPlace != winner && fourthPlace != thirdPlace )
foundFourth = true;
}
cout << "Winner: " << turtle[winner] << endl;
cout << "Second place: " << turtle[secondPlace] <<endl;
cout << "Third place: " << turtle[thirdPlace] <<endl;
cout << "Fourth place: " << turtle[fourthPlace] <<endl;
cout << "\nCONGRATULLATIONS! "<< turtle[winner]<<endl;
cout << "Your turtle has won and your money has beed doubled!\n";
cout << "TRY AGAIN AND BE RICH!" <<endl;
return 0;
}