Hi everyone,
this is my first time posting here so i apologize in advance if i am posting something wrong. I am creating a simple program for class that takes the information in from a data file and then outputs it on the screen. i have figured this part out relatively easily, but one of the requirements of the project is to have condition for the number of lines (<=9,>=11). i am completely stuck and cannot figure out where to go from here. posted below is the assignment and what i have come up with so far. thank you for your time.
ASSIGNMENT:
You will be developing C++ program to report the Truck Tire readings which was collected manually. The first thing you have to 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.
DATA FROM TRUCKTIRETEMP.TXT: 65,77,68,80,59,78,79,89,58,69
ASSIGNMENT (part i'm struggling with):
WARNING MESSAGE:
-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.
-You do not need to establish a loop here. This is a one shot deal.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int x = 1;
string line;
ifstream myfile("TruckTireTemp.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
cout << "Tire # " << x << " Pressure=" << line << " Psi" << endl;
x++;
}
myfile.close();
}
else cout << "Ooops!!Unable to open file";
system("pause");
return 0;
|
Thank you for taking the time to help, i know its probably something extremely simple, but it has me tearing my hair out at this point.