1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#include <iostream>
#include <iomanip>
#include <string>
//#include <stdio.h>
using namespace std;
using std::cout;
using std::endl;
using std::cin;
using std::string;
//=========================================================
//FUNCTION PROTOTYPES - These always go above Main
void printArray(double[], int);
void userInputArray(double array[], int size);
int userInputDriver(std::string[], int size);
int userInputCarColor(std::string[], int size);
//int getMin() {return seconds / 60);
//int getSec() {return seconds % 60};
int userInputLapTime(std::string[], int size);
void printPosition(double array[], int size);
//==========================================================
//MAIN BLOCK - Functions get called from this location
int main()
{
double carnumber[3];
string driver_name[3];
string CarColor[3];
string LapTime[3];
double position[3];
//carnumber[0] = 0;
//carnumber[1] = 1; //Can add a Welcome Message
//carnumber[2] = 2;
userInputArray(carnumber, 3);
userInputDriver(driver_name, 3);
userInputCarColor(CarColor, 3);
userInputLapTime(LapTime, 3);
printPosition(position, 3);
}
//===========================================================
//DEFINE FUNCTIONS HERE
void printArray(double array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << array[i] << endl;
}
}
//Input Array for User to choose a Car Number
void userInputArray(double array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << "Choose a carnumber ? " << endl;
cin >> array[i];
if (cin.fail()) {
cout << "Sorry, that was not a valid input" << endl; //This prints, but I need the program to end, when triggered.
cin.clear();
cin.ignore();
}
}
}
//Input Array for the Drivers Name
int userInputDriver(std::string array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << "What is the drivers name ? " << endl;
cin >> array[i];
if (cin.fail()) {
cout << "Sorry, that was not a valid input" << endl; //This prints, but I need the program to end, when triggered.
cin.clear();
cin.ignore();
return 0;
}
}
}
//Input Array for the Car Color
int userInputCarColor(std::string arrray[], int size)
{
for(int i = 0; i < size; i++)
{
cout << "What color is the car ? " << endl;
cin >> array[i];
if (cin.fail()) {
cout << "Sorry, that was not a valid input" << endl; //This prints, but I need the program to end, when triggered.
cin.clear();
cin.ignore();
return 0;
}
}
}
//Input Array for the LapTime
int userInputLapTime(std::string array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << "Please enter the Lap Time ? " << endl;
cin >> array[i];
if (cin.fail()) {
cout << "Sorry, that was not a valid input" << endl; //This prints, but I need the program to end, when triggered.
cin.clear();
cin.ignore();
return 0;
}
}
}
void printPosition(double array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << array[i] << endl;
}
}
//check if car1 came in first
{if(time1 < time2 && time1 < time3)
{
if(time1 < time2) //if he did, then check to see where car2 and car3 placed
{
cout << car1 << color1 << " came in first with a score of " << time1 << endl;
cout << car2 << color2 <<" came in second with a score of "<< time2 << endl;
cout << car3 << color3 <<" came in third with a score of "<< time3 << endl;
}
else
{
cout << car1 << color1 << " came in first with a score of "<< time1 << endl;
cout << car3 << color3 << " came in second with a score of "<< time3 <<endl;
cout << car2 << color2 << " came in third with a score of "<< time2 << endl;
}
}
{
// check if car2 came first
if(time2 < time1 && time2 < time3)
{
if(time1 < time3) //if he did, then check to see where car1 and car3 placed
{
cout << car2 << color2 << " came in first with a score of "<< time2 << endl;
cout << car1 << color1 << " came in second with a score of "<< time1 << endl;
cout << car3 << color3 << " came in third with a score of "<< time3 << endl;
}
else
{
cout << car2 << color2 << " came in first with a score of "<< time2 << endl;
cout << car3 << color3 << " came in second with a score of "<< time3 << endl;
cout << car1 << color1 << " came in third with a score of "<< time1 << endl;
}
}
// check if car3 came first
if(time3 < time1 && time3 < time2)
{
if(time2 < time1) //if he did, then check to see where car1 and car2 placed
{
cout << car3 << color3 << " came in first with a score of "<< time3 << endl;
cout << car2 << color2 << " came in second with a score of "<< time2 << endl;
cout << car1 << color1 << " came in third with a score of "<< time1 << endl;
}
else
{
cout << car3 << color3 << " came in first with a score of "<< time3 << endl;
cout << car1 << color1 << " came in second with a score of "<< time1 << endl;
cout << car2 << color2 << " came in third with a score of "<< time2 << endl;
return 0;
}
}
}
}
//system("PAUSE");
// return EXIT_SUCCESS;
|