0
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int userInput(int& Length, char& AuthorLevel);
int computePay(int& Length, char& AuthorLevel);
int main(void)
{
int Length; // The length of the story.
int counter = 0;
int numA = 0;
int numB = 0;
int numC = 0;
char AuthorLevel; // The level of the author.
float PayOut; // The final payout.
float averagePayout = 0.0;
float highestPayout = 0.0;
userInput(Length, AuthorLevel);
computePay(Length, AuthorLevel);
system("pause");
return 0;
} //end main()
//==================================================================
int userInput(int& Length, char& AuthorLevel)
{
cout << "Please enter the word count of the story (-1 to stop): ";
cin >> Length;
if(Length != -1)
{
cout << "Now enter the author's level (A, B, or C): ";
cout << "Level: ";
cin >> AuthorLevel;
cout << endl;
}
else
{
system("pause");
return 0;
}
}
//==================================================================
int computePay(int& Length, char& AuthorLevel)
{
float PayOut; // The final payout.
int numA = 0; // Number of A's that have been printed.
int numB = 0; // Total number of B's.
int numC = 0; // Number of C's.
float averagePayout = 0.0;
float highestPayout = 0.0;
int counter = 0; // The number of times the program has ran.
while(Length != -1)
{
if(Length < 7500 || Length != -1)
{
PayOut = 0.08 * Length;
}
else if(Length < 8000)
{
PayOut = 600;
}
else if(Length < 17500)
{
PayOut = 0.075 * Length;
}
else if(Length < 19000)
{
PayOut = 1313;
}
else if(Length >= 19000)
{
PayOut = 0.07 * Length;
};
if (AuthorLevel == 'A' || AuthorLevel == 'a')
{
numA++;
PayOut = 1.75 * PayOut;
}
else if(AuthorLevel == 'B' || AuthorLevel == 'b')
{
numB++;
PayOut = 1.25 * PayOut;
}
else if (AuthorLevel == 'C' || AuthorLevel == 'c')
{
numC++;
PayOut = 1.00 * PayOut;
}
else
{
cout << "That was not a valid input. Please try again." << endl;
};
userInput(Length, AuthorLevel);
counter++;
cout << "The amount the author will make from the story will be: $" << PayOut;
cout << endl << endl;
cout << "The number of payments calculated is: " << counter << endl;
cout << "The number of A's inputted: " << numA << endl;
cout << "The number of B's inputted: " << numB << endl;
cout << "The number of C's inputted: " << numC << endl;
averagePayout = (averagePayout += PayOut)/counter;
if(highestPayout < PayOut)
{
highestPayout = PayOut;
}
else if(highestPayout > PayOut)
{
highestPayout = highestPayout;
}
cout << "The highest payout so far has been: $" << highestPayout << endl;
cout << "The average payout is: $" << averagePayout << endl << endl;
}
}
//===================================================
這個程序一直工作之前多次輸出所述第一功能,並且所述第一輸出的第一,第二功能保持用於第一輸入輸出的輸入,以及 - 1不會像它應該那樣停止整個程序。誰能幫忙?問題及與輸出/輸入延遲/複製
謝謝!對於averagePayout =(averagePayout + = PayOut)/ counter;我想,如果它是不明確的,以計算已打印的所有支出,遺憾的平均值。隨着NUMA,麻木了,NUMC,變量,我試圖讓一共有多少A的,B公司和C公司已經輸入。 – DPuskas96