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
8 Respostas
+ 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;
}
+ 9
you'r welcome..😉
ask if you have any question.
+ 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;
}
+ 8
already done, you can insert 4 names separated by space
+ 1
this is morw complicated 😂 but thank you ao much 😍
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;
}
0
@mohammad dakdouk
can you also please display the third and fourth placer? thank you
0
i mean, i also want to cout the fourth place winner, and the thirdplace winner