C ++嵌套循环分配问题

时间:2017-03-31 01:23:53

标签: c++

我需要这个嵌套循环赋值的帮助。在此作业中,您将为物业管理公司开发一个C ++程序,该程序使用文件和嵌套循环写入文件并从文件中读取。该计划将计算公司收取的总租金,公司每月平均收取的租金,显示最高的收入复杂,并在任何复合体输入零租金时显示警告信息。到目前为止,我有以下内容,我不知道我将如何进入这条路线的最高位置。

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    ifstream inputFile;
    inputFile.open("complexRents.txt");

    double months;
    double complexMain;
    double complexClay;
    double complexKing;
    double totalRent = 0;
    double averageRent;
    double highRent;
    double highestRent;
    double allAverage;
    int numComplex;
    int numMonths;

    cout << fixed << showpoint << setprecision(1);
    cout << " How many complexes will you enter? ";
    cin  >> numComplex;
    cout << " How many months of rent will you input? ";
    cin  >> numMonths;

    for (int complex = 1; complex <= numComplex; complex++)
    {

        for (int rent = 1; rent <= numMonths; rent++)

        {
            double rentCost;
            cout << " Enter rent month " << rent << " for complex #" << complex                << "  : ";
            cin >> rentCost;
            totalRent += rentCost;
            highRent = totalRent;

        }
            cout << " " << highRent << endl; 
            cout << " " << endl;

    } 


    double totalMonths;
    totalMonths = numMonths * numComplex;
    averageRent = totalRent / totalMonths;
    cout << " Average rent = $ " << averageRent << endl;
    cout << endl;
    cout << " Total rent collected = $ " << totalRent << endl;


    inputFile.close();
    system("PAUSE");
    return 0;
}

0 个答案:

没有答案