程序从不输出任何输出
Program never prints any output
#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
变量
相关文章:
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 代码编译没有任何输出,入门程序
- 可能我知道为什么这段代码没有给出任何输出吗?
- 什么是现实中的"endl"(或任何输出操纵器)?它是如何实现的,它如何与操作员<<一起工
- 为什么下面的Hello World程序在PowerShell上没有显示任何输出?同一程序在CMD上显示正确的输出
- 执行此代码时,它不显示任何输出.为什么?
- 合并排序没有给我任何输出
- 编译器没有显示错误,但我没有得到任何输出.怎么了?
- 是给定代码中的任何更改,以便我可以为问题提供正确的输出
- 为什么我的代码在终端中没有输出任何内容.开始新行没有错误
- 无法输出任何内容
- 为什么这个程序不输出任何东西
- 函数不会从向量输出任何内容C++
- 提升 BCP 不输出任何文件?
- 按回车键后,程序没有输出任何结果.为什么会这样
- 任何 c++ 程序都不会输出任何内容
- 程序从不输出任何输出
- 为什么程序开头的cout语句没有输出任何东西?
- 为什么这个openGL代码没有输出任何东西
- 为什么signalhandler不输出任何东西?