Prompt:
Write a program that asks the names of three runners and
the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Input Validation: only accept positive integers for the times.
My try:
// ThreeNames.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
bool runner1;
bool runner2;
bool runner3;
cout << "What was the time of the first runner? " << endl;
//cingetline(runner1);
cin >> runner1;
cout << "What was the time of the second runner?" << endl;
cin >> runner2;
cout << "What was the time of the third runner? " << endl;
cin >> runner3;
// spacex5 = " ";
cout <<"Runners: "<<endl<< runner1<<endl << runner2<<endl << runner3<<endl;
if (runner1 > runner2 > runner3)
{
cout << "1st place: " << runner1 << endl;
cout << "2nd place: " << runner2 << endl;
cout << "3rd place: " << runner3 << endl;
}
else if (runner2 > runner3 > runner1)
{
cout << "1st place: " << runner2 << endl;
cout << "2nd place: " << runner3 << endl;
cout << "3rd place: " << runner1 << endl;
}
else if (runner3 > runner1 > runner2)
{
cout << "1st place: " << runner3 << endl;
cout << "2nd place: " << runner1 << endl;
cout << "3rd place: " << runner2 << endl;
}
else if(runner3 == runner2 == runner1)
{
cout << "All runners finished at the same time" << endl;
}
std::cout << "End of Code!\n";
return 0;
}
Thank you for helping out!