Created
September 17, 2018 20:23
-
-
Save jishanshaikh4/12a677439f08dc901fe442a7d2be32a2 to your computer and use it in GitHub Desktop.
Code for three runners time and position.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
char prevrun1, prevrun2, prevrun3; | |
string run1, run2, run3; | |
int time1, time2, time3; | |
int prevtime1, prevtime2, prevtime3; | |
void formatt(int time){ | |
if(time < 0) | |
cout << "Negative time"; | |
if(time < 60){ | |
cout << time << " seconds" << endl; | |
} | |
else if(time > 60 && time < 3600){ | |
int sec = time % 60; | |
int min = time / 60; | |
cout << min << " minutes " << sec << " seconds." << endl; | |
} | |
else{ // case for time > 3600 | |
int tempo = time % 3600; | |
int hour = time / 3600; | |
int min = tempo / 60; | |
int sec = tempo % 60; | |
cout << hour << " hours " << min << " minutes " << sec << " seconds" << endl; | |
} | |
return; | |
} | |
void takeRunnerNames(){ | |
cout << "Enter runners names: " << endl; | |
cout << "Enter runner 1 name: " << endl; | |
cin >> run1; | |
cout << "Enter runner 2 name: " << endl; | |
cin >> run2; | |
cout << "Enter runner 3 name: " << endl; | |
cin >> run3; | |
return; | |
} | |
void takeRunnerTime(){ | |
cout << "Enter runners times in seconds: " << endl; | |
cout << "Enter runner 1 time: " << endl; | |
cin >> time1; | |
cout << "Enter runner 2 time: " << endl; | |
cin >> time2; | |
cout << "Enter runner 3 time: " << endl; | |
cin >> time3; | |
if(time1 <0 || time2 < 0 || time3 < 0) | |
cout << "Negative time values." << endl; | |
return; | |
} | |
void takePreviousData(){ | |
cout << "Enter previous runners status as Y/y for yes and N/n for no: " << endl; | |
cout << "Enter runner 1 status y or n OR Y or N: " << endl; | |
cin >> prevrun1; | |
if(prevrun1 == 'Y' || prevrun1 == 'y'){ | |
cout << "Enter previous time for runner 1" << endl; | |
cin >> prevtime1; | |
} | |
cout << "Enter runner 2 status: " << endl; | |
cin >> prevrun2; | |
if(prevrun2 == 'Y' || prevrun2 == 'y'){ | |
cout << "Enter previous time for runner 2" << endl; | |
cin >> prevtime2; | |
} | |
cout << "Enter runner 3 status: " << endl; | |
cin >> prevrun3; | |
if(prevrun3== 'Y' || prevrun3 == 'y'){ | |
cout << "Enter previous time for runner 3" << endl; | |
cin >> prevtime3; | |
} | |
if(prevtime1 < 0 || prevtime2 < 0 || prevtime3 < 0) | |
cout << "Negative time" << endl; | |
return; | |
} | |
void printResults(){ | |
int maxx, minn; | |
if(time1 >= time2 && time1 >= time3) | |
maxx = 1; | |
else if(time2 >= time1 && time2 >= time3) | |
maxx = 2; | |
else | |
maxx = 3; | |
if(time1 <= time2 && time1 <= time3) | |
minn = 1; | |
else if(time2 <= time1 && time2 <= time3) | |
minn = 2; | |
else | |
minn = 3; | |
cout << "Position 1 is achieved by runner " << minn << endl; | |
if(maxx != 1 && minn != 1){ | |
cout << "Position 2 is achieved by runner " << 1 << endl; | |
} | |
else if(maxx != 2 && minn != 2){ | |
cout << "Position 2 is achieved by runner " << 2 << endl; | |
} | |
else if(maxx != 3 && minn != 3){ | |
cout << "Position 2 is achieved by runner " << 3 << endl; | |
} | |
cout << "Position 3 is achieved by runner " << maxx << endl; | |
return; | |
} | |
void printImprovements(){ | |
if(prevrun1 == 'Y' || prevrun1 == 'y'){ | |
cout << "Improvement for runner 1 is " << (prevtime1 - time1) << endl; | |
} | |
if(prevrun2 == 'Y' || prevrun2 == 'y'){ | |
cout << "Improvement for runner 2 is " << (prevtime2 - time2) << endl; | |
} | |
if(prevrun3 == 'Y' || prevrun3 == 'y'){ | |
cout << "Improvement for runner 3 is " << (prevtime3 - time3) << endl; | |
} | |
return; | |
} | |
void printAverage(){ | |
if(prevrun1 == 'Y' || prevrun1 == 'y'){ | |
cout << "Average for runner 1 is " << (prevtime1 + time1) / 2 << endl; | |
} | |
if(prevrun2 == 'Y' || prevrun2 == 'y'){ | |
cout << "Average for runner 2 is " << (prevtime2 + time2) / 2 << endl; | |
} | |
if(prevrun3 == 'Y' || prevrun3 == 'y'){ | |
cout << "Average for runner 3 is " << (prevtime3 + time3) / 2 << endl; | |
} | |
return; | |
} | |
int main(){ | |
takeRunnerNames(); | |
takeRunnerTime(); | |
takePreviousData(); | |
printResults(); | |
printImprovements(); | |
printAverage(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment