简单的问题,是的,没有问题 [英] Simple problem with yes no question

查看:52
本文介绍了简单的问题,是的,没有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,几乎现在就写这个程序一个星期了,我拥有了所需的一切,并且可以正常工作.现在,我要执行的操作(程序将根据工作时间,税金等来计算收入)是,如果用户输入他们一周内工作超过60小时,则提示会询问他们是否要超过60小时的限制并继续计算结果.因此,当要求超越60小时限制时,是"继续计算和程序,而否"则停止程序.这是我遇到问题的部分.我的问题是在第一组嵌套if循环的末尾.这是代码

Ok writing this program for a week almost now and i have everything the way i need it and it works. Now what I am trying to do (the program calculates income based off of hours worked, taxes, etc) is if the user enters that they worked more than 60 hours in one week the prompt asks them if they want to override the 60 hour limit and continue calculating the result. So when asked to override the 60 hour limit "yes" continues the calculations and program and "no" stops the program. This is the part i am having issues with. My issue is at the END of the first set of nested if loops. here is the code

// Program Project 4.cpp : Defines the entry point for the console application.
//Program that allows the user to take a name, hours worked, and hourly pay and calculate the gross pay, state and federal income tax withholdings as well as overtime pay for hours worked over 40 in 1 week


#include "stdafx.h"											
#include 
#include 
#include 

using namespace std;										

void pause()													
{ 
char junk;
cin.ignore();
cin.get(junk);
}





int main()						
{
	//declare variables

	string name, yes, no; 
	bool answer;
	double GetPay, GetHrs, PrintStub;
	double CalcFICA, CalcFedTax, CalcStateTax, GetRate, CalcFICA2, CalcFedTax2, CalcStateTax2, PrintStub2;
	double OverTime;
	
	
	
	cout << fixed << setprecision (2);	//numbers continue for 2 spaces past decimal point		
	
	//input

	cout << "What is the employees name?: "; //ask for name
	cin >> name;                   //entered input becomes name variable
	cout << "\n\n";
	cout << "What is the hourly rate of pay for this employee?: ";   // ask hourly pay
	cin >> GetRate;                //entered input becomes name variable
	cout << "\n\n";
	cout << "How many hours did this employee work?: ";  //ask for hours worked
	cin >> GetHrs;                 //entered input becomes name variable
	cout << "\n\n";

	//calculations for pay of hours

	GetPay = GetRate * GetHrs;
	OverTime = GetRate * 1.5 + GetPay;
	
	//statements for hours worked	

	{	
		if (GetHrs < 0) //if input hours are less than zero
		{
			cout << "Invalid number of hours"; //state that the input is invalid
		}
		else
			if (GetHrs <= 40) //if hours are less than 40 no overtime calculations needed
			{ 
				cout << name << ", your gross income before taxes is: $" << GetPay << "\n\n\n\n" ;
			}
				else
					if (( GetHrs >= 40) && (GetHrs <= 60)) //if 40 hours to 60 hours then output gross income
					{
						cout << name << ", your gross income before taxes is: $" << OverTime <<"\n\n\n\n";
					}
						else //if more than 60 hours ask if they want to override the limit of 60 hours
						{ 
							cout << "Excessive hours detected. Would you like to override the limit?  y/n ";
						   // cin >> answer;
					
	                 // if (answer = "y" )
					 // {
						  cout << name << ", your gross income before taxes is: $" << OverTime <<"\n\n\n\n";
					  }
					 //} 

	}

	 //statements for the hourly payrate

      {
		if ( GetRate < 5.5)  //if hourly rate of pay is under 5.5 it's slave labor and tell them it's invalid on screen
		{cout << "The hourly wages you have entered is invalid\n\n";
		}
		else 
			if (( GetRate > 5.5) && ( GetRate < 200)) //if hourly rate of pay is over 5.5 or under 200 no output to screen
			{
				cout << "";
			}
			else
				if (GetRate > 200)
				{
					cout << "The hourly wages you have entered are excessively high\n\n"; //if hourly rate of pay is over 200 say excessively high
				}
				}

	cout << "Deductions: \n\n";	

	//statement calculating FICA deductions

	CalcFICA = GetPay * .0765; //Fica rate if hours are less than 40
	CalcFICA2 = OverTime * .0765;// Fica rate if hours are more than 40

	{
		if (GetHrs < 40) //if hours less than 40
		{
			cout << "Your FICA deduction is: $" << CalcFICA << "\n\n"; 
		}
		else             //if hours are 40 or over
			{
				cout << "Your FICA deduction is: $" << CalcFICA2 << "\n\n";
		}}


	//statement for the federal tax withholdings

	CalcFedTax = GetPay * .22; //federal tax rate for no overtime
	CalcFedTax2 = OverTime * .22; //federal tax rate for overtime
	{
		if (GetHrs < 40) //of hours worked are less than 40
		{
			cout << "Your Federal Tax witholdings are: $" << CalcFedTax << "\n\n";
		}
		else       //if hours worked are 40 or over
		{
			cout << "Your Federal Tax withholdings are: $" << CalcFedTax2 << "\n\n";
		}}
	 

	//calculations for State Tax withholdings from pay
	
	CalcStateTax = GetPay * .12;   
	CalcStateTax2 = OverTime * .12;
	{
		if (GetHrs < 40)//if under 40 hours worked
		{
			cout << "Your State Tax withholdings are: $" << CalcStateTax << "\n\n";
		}
		else // if 40 hours or more worked
		{
			cout << "Your State Tax withholdings are: $" << CalcStateTax2 << "\n\n";
		}}

	//statement for Net Pay total after subtracting all withholdings

	PrintStub = GetPay - (CalcFICA + CalcFedTax + CalcStateTax); // PrintStub(NetPay) = Total amount made minus all withholdings
	PrintStub2 = OverTime - (CalcFICA2 + CalcFedTax2 + CalcStateTax2); // PrintStub(NetPay) = Total amount made with overtime included minus all withholdings
	{
		if (GetHrs < 40) //if under 40 hours worked
		{
			cout << "Your Net pay for this week will be: $" << PrintStub;
		}
		else // if 40 hours or more worked
		
		{
			cout << "Your Net pay for this week will be: $" << PrintStub2;
		}}

	//pause

	pause();
	return 0;
}

推荐答案

"<< GetPay<< \ n \ n \ n \ n"; } 其他 如果((GetHrs> = 40 )&&(GetHrs< = 60 ))// 如果40到60个小时则输出总收入 { cout<<名称<< "
" << GetPay << "\n\n\n\n" ; } else if (( GetHrs >= 40) && (GetHrs <= 60)) //if 40 hours to 60 hours then output gross income { cout << name << ", your gross income before taxes is:


" < ;<超时<< " ; } 其他 // 如果超过60小时,请问是否要超过60小时的限制 { cout<< " // cin>>答案; // 如果(answer ="y") // { cout<<名称<< "
" << OverTime <<"\n\n\n\n"; } else //if more than 60 hours ask if they want to override the limit of 60 hours { cout << "Excessive hours detected. Would you like to override the limit? y/n "; // cin >> answer; // if (answer = "y" ) // { cout << name << ", your gross income before taxes is:


" < ;<超时<< " ; } // } } // 小时工资声明 { 如果(GetRate< 5 . 5 )// ,如果小时工资低于5.5,则为奴役,并在屏幕上告诉他们无效 {cout<< " ; } 其他 如果(((GetRate> 5 . 5 )&&(GetRate< 200 ))// " ; } 其他 如果(GetRate> 200 ) { cout<< " // 如果时薪超过200,则说过高 } } cout<< " ; // 计算FICA扣除额的声明 CalcFICA = GetPay *. 0765 ; // 小时数少于40的费用率 CalcFICA2 =超时*. 0765 ; // 小时超过40 { 如果(GetHrs< 40 )// 如果小时数少于40 { cout<< "
" << OverTime <<"\n\n\n\n"; } //} } //statements for the hourly payrate { if ( GetRate < 5.5) //if hourly rate of pay is under 5.5 it's slave labor and tell them it's invalid on screen {cout << "The hourly wages you have entered is invalid\n\n"; } else if (( GetRate > 5.5) && ( GetRate < 200)) //if hourly rate of pay is over 5.5 or under 200 no output to screen { cout << ""; } else if (GetRate > 200) { cout << "The hourly wages you have entered are excessively high\n\n"; //if hourly rate of pay is over 200 say excessively high } } cout << "Deductions: \n\n"; //statement calculating FICA deductions CalcFICA = GetPay * .0765; //Fica rate if hours are less than 40 CalcFICA2 = OverTime * .0765;// Fica rate if hours are more than 40 { if (GetHrs < 40) //if hours less than 40 { cout << "Your FICA deduction is:


这篇关于简单的问题,是的,没有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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