gpt4 book ai didi

C++ 代码在 GDB online 中有效,但在代码 :Blocks 中无效

转载 作者:行者123 更新时间:2023-11-28 04:47:58 25 4
gpt4 key购买 nike

<分区>

我不明白为什么我的程序在 GDB online 中可以运行,但在 Code:Blocks 中却不能运行。它应该允许一个人输入他们的小时费率,然后输入他们在过去 4 周内工作了多少小时,将这些总数加在一起并将总数返回给用户。它应该使用一个以小时为参数的函数。在 Code:Blocks 中,它在输入第一个小时数后终止程序。这是代码:

#include <iostream>
#include <iomanip>
using namespace std;

// function declaration
float getGross(float hs[], int n);

int main()
{

float hours[4], sum;
sum = getGross(hours, 4);
cout << "Gross pay: $ " << setprecision(2) << fixed << sum << endl;
return 0;

}

// function definition
float getGross(float hs[], int n)
{
float wage, ot, total;

cout << "Please enter your hourly wage: " << endl;
cin >> wage;

cout << "Enter hours worked in each of the past four weeks (hit enter after each entry): " << endl;
// Storing 4 number entered by user in an array

for (int i = 0; i < n; ++i)
{
// Holding the array of hours entered
cin >> hs[i];

int j;
float weekPay[4];

if(hs[i] > 40)
{
ot = (hs[i] - 40) * 1.5;
weekPay[j] = (wage * 40) + (ot * wage);
total += weekPay[j];
}
else
{
weekPay[j] = (wage * hs[i]);
total += weekPay[j];
}
}

return total;
}

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