PLEASE VIEW MY CODE IN COMMENT SECTION. Can anyone edit it so i could enter the name of horse 1 horse 2. I want to cout and cin. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

PLEASE VIEW MY CODE IN COMMENT SECTION. Can anyone edit it so i could enter the name of horse 1 horse 2. I want to cout and cin.

HELP! PLEASE

21st May 2017, 3:51 AM
eiro Jan
eiro Jan - avatar
8 Answers
+ 9
#include <iostream> #include <array> #include <ctime> #include <cstdlib> using namespace std; int main() { cout <<"THE TURTLE RACE"<<endl; const int numberOfHorses = 4; array<string,4> horse; srand(time(NULL)); cout << "\n\nEnter the name of the 4 hourses separated by spaces:\n\n"; for(int i = 0; i < 4; i++){ cin >> horse[i]; } int winner; winner = rand() % numberOfHorses; int secondPlace; bool foundSecond = false; while(!foundSecond) { secondPlace = rand() % numberOfHorses; if(secondPlace != winner) foundSecond = true; } cout << "winning horse: " << horse[winner] << endl; cout << "second place: " << horse[secondPlace] <<endl; return 0; }
21st May 2017, 4:13 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 9
you'r welcome..😉 ask if you have any question.
21st May 2017, 4:23 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 9
#include <iostream> #include <array> #include <ctime> #include <cstdlib> using namespace std; int main() { cout <<"THE TURTLE RACE"<<endl; const int numberOfHorses = 4; array<string,4> horse; srand(time(NULL)); cout << "\n\nEnter the name of the 4 hourses separated by spaces:\n\n"; for(int i = 0; i < 4; i++){ cin >> horse[i]; } int winner; // here will chose the winner winner = rand() % numberOfHorses; 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() % numberOfHorses; if(secondPlace != winner) foundSecond = true; } // here we get the third place while(!foundThird ) { thirdPlace = rand() % numberOfHorses; if(thirdPlace != secondPlace && thirdPlace != winner) foundThird = true; } // here we get the fourth place while(!foundFourth ) { fourthPlace = rand() % numberOfHorses; if( fourthPlace != secondPlace && fourthPlace != winner && fourthPlace != thirdPlace ) foundFourth = true; } cout << "winning horse: " << horse[winner] << endl; cout << "second place: " << horse[secondPlace] <<endl; cout << "third place: " << horse[thirdPlace] <<endl; cout << "fourth place: " << horse[fourthPlace] <<endl; return 0; }
21st May 2017, 4:43 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 8
already done, you can insert 4 names separated by space
21st May 2017, 4:25 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 1
this is morw complicated 😂 but thank you ao much 😍
21st May 2017, 4:20 AM
eiro Jan
eiro Jan - avatar
0
#include <iostream> #include <array> #include <ctime> #include <cstdlib> using namespace std; int main() { cout <<"THE TURTLE RACE"<<endl; const int numberOfHorses = 4; array<char,4> horse; srand(time(NULL)); horse[0] = 'A'; horse[1] = 'B'; horse[2] = 'C'; horse[3] = 'D'; int winner; winner = rand() % numberOfHorses; int secondPlace; bool foundSecond = false; while(!foundSecond) { secondPlace = rand() % numberOfHorses; if(secondPlace != winner) foundSecond = true; } cout << "winning horse: " << horse[winner] << endl; cout << "second place: " << horse[secondPlace] <<endl; return 0; }
21st May 2017, 3:53 AM
eiro Jan
eiro Jan - avatar
0
@mohammad dakdouk can you also please display the third and fourth placer? thank you
21st May 2017, 4:22 AM
eiro Jan
eiro Jan - avatar
0
i mean, i also want to cout the fourth place winner, and the thirdplace winner
21st May 2017, 4:27 AM
eiro Jan
eiro Jan - avatar