I am having trouble with the error part of my program.
You will be developing C++ program to report the Truck Tire readings which was collected manually.The first thing you have to do is to prepare an input data
file. Name of the file must be TruckTireTemp.txt. Make a notepad file ( .txt) in your computer for the Truck Tire temperature readings and enter (simply type in) the following tire temp readings from Dump Truck #1 ( 10 Wheels). And, Save this file where you have the source code( the default location on your computer is under MS Visual Studio / Projects..) . Then close this input data file.
I did this part but im stuck on this next part....
If the input data file contains 9 or less tire data then “Error, file has less than 10 wheels. Check your input data file and re-run the code” . Then, the program stops here.
If the input data file contains 11 or more tire data then “Error, file has more than 10 wheels. Check your input data file and re-run the code” . Then, the program stops here.
Data file:
65
77
68
80
59
78
79
89
58
69
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
|
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main() //Starting the body of the code
{
int I = 1, pressure;
ifstream myfile("TruckTireTemp.txt");
while (myfile >> pressure) {
cout << "Tire # " << I << "\tTire pressure = " << pressure << "\tPsi" << endl;
I++;
}
{
if (I <= 9)
{
cout << "\nError, file has less than 10 wheels. Check your input data file and re-run the code\n";
}
else if (I >= 11)
{
cout << "\nError, file has more than 10 wheels. Check your input data file and re-run the code\n";
}
else
{
}
}
cout << endl << endl;
system("pause");
return 0;
}
|
When there are 9 numbers in the data file it does not print an error
And when there is 10 numbers it does print in error
I am confused. Please help.