こんにちは私がしたいのは、最も高い賃貸料とアパート名を持つアパートがあれば、最後の声明文が表示されます。今すぐ入力されたすべての複合体の総家賃と最後に入力された複合名が表示されます。私はこれに固執して、実際にこれについていくつかの助けを使用することができます。私はC++を初めて使っているので、素人の言葉で私に話してください。何かを理解することは難しいです。それは私です場合は、次のようにループ内のステートメントが読めない場合right right coutが正しく表示されない
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ofstream outputFile;
outputFile.open("rentfile.txt");
int numComplex, numMonths;
double rent, totalAllRent = 0; //// Accumulator for total scores
string nameComplex;
string highNameComplex;
double averageRent;
double highestRentTotal = 0;
//set up numeric output programing
cout << fixed << showpoint << setprecision(1);
cout << "How many complexes will you enter?";
cin >> numComplex; //number of complexes enter
cout << "How many months of rent will you enter complex?";
cin >> numMonths; //number of months of rent enter
for (int complex = 1; complex <= numComplex; complex++)
{
cout << "Enter Complex Name ";
cin >> nameComplex;
outputFile << nameComplex << " ";
for (int months = 1; months <= numMonths; months++)
{
cout << "Enter Rent " << months << " for ";
cout << " Complex " << complex << ": ";
cin >> rent;
outputFile << rent << endl; //write data to output file
totalAllRent = totalAllRent + rent;
if (totalAllRent > highestRentTotal)
{
highNameComplex = nameComplex;
highestRentTotal = totalAllRent;
}
averageRent = totalAllRent/numComplex;
}
}
outputFile.close(); //close the file
ifstream inputFile;
inputFile.open("rentfile.txt");
cout << "Complex Monthly rent Collected per Complex " << endl;
while (inputFile >> nameComplex)
{
for (int i = 0; i < numMonths; i++)
{
inputFile >> rent;
cout << nameComplex << " " << rent << endl;
if (rent == 0)
cout << "Warning one of the complexes submitted zero rent for one of the months " << endl;
}
}
cout << "Total rent collected for the company = " << totalAllRent << endl;
cout << " Average Monthly rent collected for the company = " << averageRent << endl;
cout << highNameComplex << "collect the most rent = " << highestRentTotal << endl;
system("pause");
return 0;
}