gpt4 book ai didi

c++ - C++调试后无显示

转载 作者:行者123 更新时间:2023-11-28 02:46:05 26 4
gpt4 key购买 nike

所以我开始了我的 C++ 项目,在案例 1 之后,决定调试并确保我没有犯任何错误。唯一的问题是,没有任何显示?没有出现错误,但输出只是空白?在假设下,我一开始就完全遗漏了一些东西。请帮忙

#include <iostream> 
#include <iomanip> // for 'fixed' and 'setprecision'
#include <cmath> // C++ Math Library

// function main begins program execution
int main()
{
double managWage = 0;
double hourlyWorkers = 0;
double commissionWorkers = 0;
double widgetWorkers = 0;

// a variable to hold their choice
char selection = 0;
while (selection != 'Q');
// a variable to track the number of transactions
int transaction = 0;
{

// Display a menu to the user
// You MUST use these integer values (1-5) for the auto evaluator to work
std::cout << "(1) Managers" << std::endl;
std::cout << "(2) Hourly Workers" << std::endl;
std::cout << "(3) Commission Workers" << std::endl;
std::cout << "(4) Widget Workers" << std::endl;

// Ask the user for their choice + Sentinel Value
std::cout << "Enter pay code <[Q]uit>";
std::cin >> selection;

switch (selection)
{
case '1':
//Variables
int weekSalary = 0;
managWage = managWage + weekSalary;

std::cout << "Manager selected." << std::endl;
std::cout << "Enter weekly salary ";
std::cin >> weekSalary;
if (weekSalary < 0)
{
std::cout << "Error: Weekly salary can not be less than zero.";
}
else
{
while (weekSalary >= 0)
{
std::cout << "Manager's pay is " << managWage << std::endl;
} //End while
break;
} //End else
break;

}
}
}

最佳答案

这是你的问题

while (selection != 'Q');

这会导致无限循环。你可能想要:

while (selection != 'Q')
{
int transaction = 0;
...

还有一个:

while (weekSalary >= 0)

关于c++ - C++调试后无显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com