I need to read these numbers from a file:
2 10.5
5 20
10 30.2
It is not working. It skips over numbers. The first row (2,5,10) is supposed to be Hours and the second row (10.5, 20, 30.2) is supposed to be Pay.Any help is appreciated.Thank you.
Note: This section is supposed to be apart of a bigger program that calculates base pay using a Function.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputFile;
string hours, pay;
// Test File.
inputFile.open("Lab12aInput.txt");
if (!inputFile)
{
cout <<"Error file does not exist.\n";
}
while (inputFile >> hours || inputFile >> pay)
{
inputFile >> hours >> pay; // Read data from file
cout << "Hours: " << hours << " and " "Pay: " << pay << endl;
}
// Close the file.
inputFile.close();
return 0;