Brief Description: This program demonstrates input/output control for an LRT system
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
// Prompt user to enter the number of trains on each track
double t1, t2, t3, t4;
cout << "Enter the number of trains on Track 1. " ;
cin >> t1;
cout << "Enter the number of trains on Track 2. " ;
cin >> t2;
cout << "Enter the number of trains on Track 3. " ;
cin >> t3;
cout << "Enter the number of trains on Track 4. " ;
cin >> t4;
// Comparison for t4
if ((t4>=t1) && (t4>=t2) && (t4>=t3));
{
cout << "Track 1 has " << t1 << " train(s) stopped." << endl ;
cout << "Track 2 has " << t2 << " train(s) stopped." << endl ;
cout << "Track 3 has " << t3 << " train(s) stopped." << endl ;
cout << "Track 4 has 1 train cleared and " << t4-1 << " train(s) stopped. " ;
if ((t4-1) > 4);
{
cout << "Track 4 alert!" << endl ;
}
cout << endl;
}
// Comparison for t3
else if ((t3>=t1) && (t3>=t2) && (t3>t4));
{
cout << "Track 1 has " << t1 << " train(s) stopped." << endl ;
cout << "Track 2 has " << t2 << " train(s) stopped." << endl ;
cout << "Track 3 has 1 train cleared and " << t3-1 << " train(s) stopped." ;
if ((t3-1) > 4);
{
cout << "Track 3 alert!" << endl ;
}
cout << "Track 4 has " << t4 << " train(s) stopped. " << endl ;
cout << endl;
}
// Comparison for t2
else if ((t2>=t1) && (t2>t3) && (t2>t4));
{
cout << "Track 1 has " << t1 << " train(s) stopped." << endl ;
cout << "Track 2 has 1 train cleared and " << t2-1 << " train(s) stopped." ;
if ((t2-1) > 4);
{
cout << "Track 2 alert!" << endl ;
}
cout << "Track 3 has " << t3 << " train(s) stopped." << endl ;
cout << "Track 4 has " << t4 << " train(s) stopped. " << endl ;
cout << endl;
}
// Comparison for t1
else if ((t1>t2) && (t1>t3) && (t1>t4));
{
cout << "Track 1 has 1 train cleared and " << t1-1 << " train(s) stopped. " ;
if ((t1-1) > 4);
{
cout << "Track 1 alert!" << endl ;
}
cout << "Track 2 has " << t2 << " train(s) stopped." << endl ;
cout << "Track 3 has " << t3 << " train(s) stopped." << endl ;
cout << "Track 4 has " << t4 << " train(s) stopped. " << endl ;
cout << endl;
}
return (0);
}
I'm writing a program to sequentially look through four train tracks, select the track with the most trains, clear one train on the selected track and stop the rest of the trains.
Should the number of trains stopped on the track with the most trains be greater than 4, an alert is displayed.
Should there be any equivalency between the number of trains on the tracks, there is a priority list: Track 4 has priority over Track 3 which has priority over Track 2 which has priority over Track 1. answers ned to be displayed in the folowing format:
Enter the number of trains on Track 1. 1 Enter the number of trains on Track 2. 5 Enter the number of trains on Track 3. 3 Enter the number of trains on Track 4. 5 Track 1 has 1 train(s) stopped. Track 2 has 5 train(s) stopped. Track 3 has 3 train(s) stopped. Track 4 has 1 train cleared and 4 train(s) stopped. Track 4 alert!
Any help would be greatly apreciated.
Aucun commentaire:
Enregistrer un commentaire