0
간단한 변경 분류 프로그램을 만들려고합니다. 모든 부분이 제대로 작동하고 있으며 분기를 감지 할 것으로 예상됩니다. 전류 출력의모든 동전을 계산하지 않습니다.
예 :
The amount you entered is: 52.50
You have this many Fifty dollars: 1
You have this many Ten dollars: 0
You have this many One: 2
You have this many Quarters: 0
원하는 출력 :
The amount you entered is: 52.50
You have this many Fifty dollars: 1
You have this many Ten dollars: 0
You have this many One: 2
You have this many Quarters: 2
코드 :
#include <iostream>
using namespace std;
const int FIFTY = 50;
const int TEN = 10;
const int ONE = 1;
const double QUARTER = 0.25;
int _tmain(int argc, _TCHAR* argv[])
{
int change;
cout << "Enter the amount of money in your wallet: ";
cin >> change;
cout << endl;
cout << "The amount you entered is: " << change << endl;
cout << "The number of Fifty dollars to be returned is: " << change/FIFTY << endl;
change = change % FIFTY;
//
cout << "The number of Ten dollars to be returned is: " << change/TEN << endl;
change = change % TEN;
//
cout << "The number of One dollars to be returned is: " << change/ONE << endl;
change = change % ONE;
//
cout << "The number of Quarters to be returned is: " << change/QUARTER << endl;
change = change % QUARTER;
return 0;
}
내가 갖는 2 개의 오류가 있습니다 :
Error 1 error C2297: '%' : illegal, right operand has type 'double'
Error2 IntelliSense: expression must have integral or unscoped enum type
제 제안은 달러가 아닌 단위로 센트를 사용하는 것입니다. 그렇게하면 정수가 아닌 형식을 처리 할 필요가 없습니다. –
모든 것을 센트로 변환하면이 문제를 피할 수 있습니다. –
'FIFTY','TEN' 및 'ONE'은 모두 정수이지만'QUARTERS '는'double '(0.25)입니다. 부동 소수점 값으로 나눌 때 나머지 부분을 가져 오는 것은 의미가 없습니다. – Eric