I recently finished an MS Project, and now gotta finish this.
The thing is I don't have access to my main computer's Windows partition (I mean write access) and some other problems.
That didn't just took my time, but made me tired also.
I will be glad if someone can find the error in this code, because I am really tired of trying and cannot think clearly anymore.
Now, as long as I do not enter more than 15 characters, everything is fine. But when I enter more than 15 characters, it displays every cout and then displays the cout that starts with "Either".
How can I fix that?
All I need to achieve is
"Be sure the names do not overflow the arrays".
I know it is Friday, and I know this is not a C++ forum, but it is the best forum on the internet!
Probably, just by looking at the red section; you will find what needs to be done easily.
Thank you.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE=16;
char f1[SIZE], f2[SIZE], f3[SIZE], l1[SIZE], l2[SIZE], l3[SIZE];
double t1, t2, t3;
cout << "This program will put the best three runner\n"
"in order of their finishing time."
"\nPlease enter runners' details.\n\n"
"***WARNING***: Last names and first names will be displayed with\n"
"the first 15 characters only and miliseconds will be displayed with\n"
"three decimal points only.\n\n";
cout << "Runner Number 1 Details\n"
"-----------------------\n"
"Last Name : ";
cin.getline(l1, SIZE);
cout << "\nFirst Name : ";
cin.getline(f1, SIZE);
cout << "\nFinish Time(In Seconds): ";
cin >> t1;
cout << "Runner Number 1 Details\n"
"-----------------------\n"
"Last Name : ";
cin.ignore();
cin.getline(l2, SIZE);
cout << "\nFirst Name : ";
cin.getline(f2, SIZE);
cout << "\nFinish Time(In Seconds): ";
cin >> t2;
cout << "Runner Number 1 Details\n"
"-----------------------\n"
"Last Name : ";
cin.ignore();
cin.getline(l3, SIZE);
cout << "\nFirst Name : ";
cin.getline(f3, SIZE);
cout << "\nFinish Time(In Seconds): ";
cin >> t3;
if (t1==t2||t1==t3||t2==t3||t1<=0||t2<=0||t3<=0)
{
cout << "\n\nEither you have entered the same finishing time for different runners\n"
"or one or more finishing time is smaller than or equal to 0.\n"
"Please restart the program and enter correct finishing times.\n\n";
system("pause");
return 0;
}
else
{
cout << "\n\nHere are the runners displayed according to their finishing time:\n\n";
if (t1<t2&&t1<t3)
{
if (t2<t3)
{
cout << "1. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "2. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "3. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << "\n\n";
}
else
{
cout << "1. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "2. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "3. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << "\n\n";
}
}
else if (t2<t1&&t2<t3)
{
if (t1<t3)
{
cout << "1. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "2. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "3. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << "\n\n";
}
else
{
cout << "1. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "2. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "3. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << "\n\n";
}
}
else
{
if (t2<t1)
{
cout << "1. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "2. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "3. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << "\n\n";
}
else
{
cout << "1. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "2. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "3. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << "\n\n";
}
}
}
system("pause");
return 0;
}