2014-09-13 2 views
0

그래, 나는 잘못된 결과를 얻는 코드를 컴파일 할 때 taxRate의 사용자 입력에 문제가 있습니다.사용자 입력이 잘못된 결과를 내고 있습니다.

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

int main() 
{ 

long propertyValue; 
long taxRate; 
long exemption = 5000; 

cout << "What is the actual value of your property?\n"; 
cin >> propertyValue; 
cout << "What is the current tax rate?\n"; 
cin >> taxRate; 

cout << "You will pay an annual property tax of "; 
cout << (propertyValue - exemption) * taxRate/100.00; 
cout << " on your property\n"; 

cout << "and your quarterly tax bill will be; "; 
cout << (propertyValue - exemption) * taxRate/100.00/4 << endl; 
system("pause"); 

return 0; 
} 
+0

먼저 입력 내용은 무엇이며, 무엇을 기대합니까? "잘못된 결과"는 무엇입니까? 둘째,'taxRate','propertyValue' 및'exemption'을 모두'long's로 설정 하시겠습니까? – MooseBoys

+0

예 : propertyValue 입력에 대해 –

+0

의 입력, 예상 출력 및 출력을 제공하십시오. 94,800이고 taxValue는 2.64 일 수 있으며, 재산세에 대한 예상 출력은 2,370이고 분기 별 세금 계산서는 592.68 – user3291461

답변

0

이것은 코드에서 간단한 오류입니다. 이유를 설명합니다.
예를 들어 PropertyValue가 300,000이고 세율이 5.6이라고 가정 해 봅시다. 당신은 연간 재산 세율의 수식을 사용 :

(PropertyValue - exemption) * taxRate/100.00; 

그리고 당신은 (일명 긴 int)를 long로서 taxRate을 선언

30

long taxRate; 
- = 295,000 * 5.6 < 5000 --- - 네 실수가 바로 여기있어! long은 int의 속성이므로 5.6이 5가됩니다. double (부동 소수점 숫자)으로 변경하면 문제가 해결됩니다. 이 코드를 여러 번 테스트했고 코드가 수정되었습니다.

+0

저를 청소 해 주셔서 감사합니다. – user3291461

관련 문제