これを実行するには、深刻な助けが必要です。inputFile でループを台無しにしていると思います。プログラムがコンパイルされ、.txt ファイルが適切なディレクトリに作成されます。txt は、ユーザー入力を置き換えるテスト ファイルです。このファイルには、1、115、および 10 の 3 つの別々の行に 3 つの数字が含まれています。これが私のコードです。
//Headers
//Headers
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstdlib>
#include<iomanip>
using
namespace std;
void PaintJobEstimator(double gallonprice, double wallspace)
{
double numBucket;
double hours;
double bucketCost;
double laborCharges;
double totalCost;
{
//calculates number of buckets of paint (gallons) needed
numBucket=1/115*wallspace;
//calculates paint cost
bucketCost=gallonprice*numBucket;
//calculates labor hour
hours=8/115*wallspace;
//calculates labor charges
laborCharges=hours*18;
//calculates total cost
totalCost=bucketCost+laborCharges;
//Console output
{
cout << "The number of Gallons of paint required:\t" << numBucket << endl;
cout << "The hours of labor required:\t" << hours << " hrs" << endl;
cout << "The labor charges:\t$" << laborCharges << endl;
cout << "The cost of the paint:\t$" << bucketCost << endl;
cout << "The total cost of the paint job:\t$" << totalCost << endl;
}
}
}
int main ()
{
int rooms=0; //number of rooms
double wallspace=0; //wall space measured in square meters
double gallonprice=0; //Price per gallon
cout << "=========================================================\n";
cout << "___________________Paint Job Estimator___________________\n";
cout << "_________________________________________________________\n";
//by Jeff Youngblood
cout << endl;
ifstream inputFile;
//open the file
inputFile.open("17.txt");
if (inputFile.is_open())
{
if (rooms>=1) //validates rooms
{
inputFile >> rooms;
}
for (int roomNum=1;roomNum<=rooms;roomNum++)
{
if (wallspace>1)//validates and inputs wallspace
{
inputFile >> wallspace;
}
}
//end loop
while (gallonprice>10) //validates price per gallon
{
inputFile >> gallonprice;
}
PaintJobEstimator(gallonprice,wallspace);
system ("pause");
}
else
cout <<"Error reading file '17.txt', please check your directory.\n";
}