程序在一段时间后冻结 [英] Program freezes after some time

查看:85
本文介绍了程序在一段时间后冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我一直致力于我的大学任务,就是编写一个程序来获取用户在公司工作的员工的意见,然后从用户那里获得他们的薪水输入。目标是计算净工资(减去税额,在下面的编码中解释),然后找到薪水较高但净工资较低的不幸的人,下面是我写的编码。现在,问题是,当我运行程序时,它运行正常并询问用户的员工,在我给出号码之后,再次运行正常并询问他们的工资,在我给了工资之后它没有做任何事情而且只是冻结,破折号一直闪烁。请帮帮我,有什么问题?这是编码:



Hello guys, I have been working on my university assignment that was to write a program to get the input of no of employees working in a company from user and then get the input of their salaries from user. The objective was to calculate the net salaries (subtracting the tax amount, explain in the coding below) and then finding the unlucky people who had higher salary but lower net salary, below is the coding I have written. Now, the problem is when I run the program, it runs fine and ask the no of employees from user, after I give number, it runs fine again and ask their salaries, after I have given salaries then it does not do anything and just freezes and the dash keep blinking. Please help me out, what is the problem? This is the coding:

#include <iostream>
using namespace std;

void getInput(double [][2], int);
void calcSal(double [][2], int);
void locUnLucky (double [][2], int [], int);
void displayOutput (double [][2], int [], int);

int main()
{
	const int arraySize= 100;
	int totalEmps;
	int lucky[] = {0};
	double sal[arraySize][2];
	
	cout << "Please enter the total number of employees working in your company: ";
	cin >> totalEmps;

	getInput(sal, totalEmps);
	
	calcSal(sal, totalEmps);
	
	locUnLucky(sal, lucky, totalEmps);
	
	displayOutput(sal, lucky, totalEmps);
	
}

void getInput(double sal[][2], int totalEmps)
{
    for (int i = 0; i < totalEmps; i++)
    {
        cout << "Please enter the gross salary in dollars for employee #" << i << ": ";
        cin >> sal[i][0];
    }
}

void calcSal(double sal[][2], int totalEmps)
{
	for (int i = 0; i < totalEmps; i++)
	{
		if (sal[i][0] <= 5000)
		{
			// no tax deduction
			sal[i][1] = sal[i][0];
		}
		
		else
		{
			if(sal[i][0] <= 10000)
			{
				// 5% tax deduction
				sal[i][1] = sal[i][0] - (0.05 * sal[i][0]);
			}
			
			else
			{
				if(sal[i][0] <= 20000)
				{
					// 10% tax deduction
					sal[i][1] = sal[i][0] - (0.1 * sal[i][0]);
				}
				
				else
				{
					// 15% tax deduction
					sal[i][1] = sal[i][0] - (0.15 * sal[i][0]);
				}
			}
		}
	}
}

void locUnLucky (double sal[][2], int lucky[], int totalEmps)
{
	int i, j, grossSalary, netSalary;
	
	for (i = 0; i < totalEmps; i++)
	{
		grossSalary = sal[i][0];
		netSalary = sal[i][1];
		
		for (j = 0; i < totalEmps; j++)
		{
			if(grossSalary > sal[i][0] && netSalary < sal[i][1])
			{
				lucky[i] = 1;
			}
		}
	}
}

void displayOutput (double sal[][2], int lucky[], int totalEmps)
{
	for (int i = 0; i < totalEmps; i++)
	{
		if (lucky[i] == 1)
		{
			cout << "Enmployee #" << i+1 << " is unlucky with $" << sal[i][0] << " as gross salary whereas $" << sal[i][1] << "as net salary" << endl;
		}
	}
}





我尝试了什么:



因为我无法理解问题所在,我还没有尝试过任何东西



What I have tried:

As I can't understand that what the problem could be, I have not tried anything

推荐答案

<< sal [i] [ 0 ]<< 作为工资总额而
" << sal[i][0] << " as gross salary whereas


<< sal [i] [ 1 ]<< as net salary<< endl;
}
}
}
" << sal[i][1] << "as net salary" << endl; } } }





我的尝试:



因为我无法理解问题是什么,我没有尝试过任何东西



What I have tried:

As I can't understand that what the problem could be, I have not tried anything


你应该学会使用调试器尽快。不是猜测你的代码在做什么,而是时候看到你的代码正在执行并确保它能达到预期的效果。



调试器允许你逐行跟踪执行,检查变量,你会发现有一点它会停止你所期望的。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么你的任务是与它应该做的事情进行比较。

调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于程序在一段时间后冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆