输出冻结了编译器,我不知道为什么... [英] Output freezes compiler, and I don't know why...
本文介绍了输出冻结了编译器,我不知道为什么...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个程序,根据客户数量来计算每小时所需的员工数量.始终必须至少有3名员工,但每20个客户还要有1名额外的员工.我使用数组和for循环编写此代码,但是在输入每小时所有客户值之后(我刚刚为9位客户使用9、10、19、20、29、30 ...),然后尝试打印结果它坏了.我不确定为什么.谢谢
I am writing a program to calculate the amount of employees needed per hour based on the amount of customers. There must be at least 3 employees at all times, but also 1 additional employee per 20 customers. I wrote this with arrays and for loops, but after I enter all my values of customers per hour (I have just been using 9, 10, 19, 20, 29, 30.... for number customers) and try to print the results it breaks. I am not sure why.... please help. THANK YOU
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Program to calculate how many employees are needed during the day based on customers
string hours[24] = {"0000-0100", "0100-0200", "0200-0300", "0300-0400", "0400-0500", "0500-0600", "0600-0700", "0700-0800", "0800-0900", "0900-1000", "1000-1100", "1100-1200", "1200-1300", "1300-1400", "1400-1500", "1500-1600", "1600-1700", "1700-1800", "1800-1900", "1900-2000", "2000-2100", "2100-2200", "2200-2300", "2300-2400"};
int customers[24], employees[24],i;
cout << "Workforce Calculator" << endl << endl;
//for loop to gather information and calculate employees
for (i=0; i <= 24; i++)
{
cout << "Please enter the amount of customers for the time period of " << hours[i] << ":" << endl;
cin >> customers[i];
employees[i] = 3 + customers[i] / 20;
}
//for loop to print results
for (i=0; i <= 24; i++)
{
cout << "The amount of employees needed to cover certain time periods is as fallows:"<< endl << endl;
cout << "For the timme period of "<< hours[i] << " you will need " << employees[i] << " employees." << endl;
}
}
推荐答案
两者的循环都运行到24(含24),但应该只运行到23.
Both of your loop run to 24 inclusive, but should run only to 23.
for (i=0; i < 24; i++)
这篇关于输出冻结了编译器,我不知道为什么...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文