程序从不输出任何输出

Program never prints any output

本文关键字:输出 任何 程序      更新时间:2023-10-16
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void userInput(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;
} //end main()
//==================================================================
// This part collects the inputs.
void userInput(int& Length, char& AuthorLevel )
{
cout << "Please enter the word count of the story (-1 to stop): ";
cin >> Length;
cout << "Now enter the author's level (A, B, or C): ";
cout << "Level: ";
cin >> AuthorLevel;
cout << endl;
};
//==================================================================
int computePay(int& Length, char& AuthorLevel)
{
    float PayOut;       // The final payout.
    int numA = 0;
    int numB = 0;
    int numC = 0;
    float averagePayout = 0.0;
    float highestPayout = 0.0;
    int counter = 0; // The number of times the program has ran.
    if(Length < 7500)
        {
            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
        {
            PayOut = 0.07 * Length;
        };
    if ((AuthorLevel == 'A') || (AuthorLevel == 'a'))
    {
        PayOut = 1.75 * PayOut;
    }
    else if(AuthorLevel == 'B' || AuthorLevel == 'b')
    {
        PayOut = 1.25 * PayOut;
    }
    else if (AuthorLevel == 'C' || AuthorLevel == 'c')
    {
        PayOut = 1.00 * PayOut;
    };
    do
    {
        userInput(Length, AuthorLevel);
        computePay(Length, AuthorLevel);
        counter++;
        cout << "The amount the author will make from the story will be: $"     << PayOut;
        cout << endl << endl;
          averagePayout = (averagePayout + PayOut) /2;
          if(highestPayout < PayOut)
            {
            highestPayout = PayOut;
             }
    }
    while(Length != -1);
};

//list the number of a b c 's
// for this use if statements to check  which was entered and then increment      that counter,
// system out the loop counter
//system out average payout and highest
//===================================================

这一直是零输出,不运行通过计算或要求输入,我真的不知道我做错了什么。对于这个作业,我还必须列出输入的A, B和C的数量,跟踪它循环了多少次,计算每次循环后的平均支出,并指出每次循环后的最大支出,我不太喜欢怎么做。有人能帮忙吗?

您的main()没有调用您定义的任何函数。它只包含变量定义。

由于这是c++,如果你的main()没有显式返回,它将返回一个0,这就是你所看到的。

我也不确定你的int computePay():它似乎没有返回任何int,即使它应该,可能吗?或者你希望它是void ?

你的代码中有多个问题:

1)。你从来没有调用任何你的功能在main()。它所做的就是创建一些变量并结束程序。试着在main中添加如下内容:

userInput(Length, AuthorLevel);

computePay(Length, AuthorLevel);

2)。你的功能int computePay(int& Length, char& AuthorLevel) &int main()被声明为返回int,但你永远不会返回任何东西:这会导致未定义的行为。只需在函数末尾添加return 0; -或将类型更改为float并返回PayOut变量。

3)。您在开始时错过了int computePay(int& Length, char& AuthorLevel);的原型,因此您将无法从主函数中调用它。

4)。你的computepay函数永远不会返回,也不会导致堆栈溢出——每次在你的循环中,你都会进行一个永远不会结束的递归调用。您需要在调用comutePay之前检查Length变量