Coin Counter 问题
一个硬币转美元美分的项目题目如下:
Write a program that asks the user to enter a number of quarters, dimes, nickels and pennies and then outputs the monetary value of the coins in the format of dollars and remaining cents.
Your program should interact with the user exactly as it shows in the following example:
Please enter the number of coins:
# of quarters: 20
# of dimes: 4
# of nickels: 13
# of pennies: 17
The total is 6 dollars and 22 cents
File Name:counter.cpp
我的代码:
#include <iostream>
using namespace std;
int main()
{
int n_of_quarters;
int n_of_dimes;
int n_of_nickels;
int n_of_pennies;
int Dollar;
int cent;
double x,y,z,h,Dollarcent,Cent;
cout<<"type the number of quarters"<<endl;
cin>>n_of_quarters;
cout<<"# of quarters: 20"<<endl;
x = n_of_quarters*0.25;
cout<<"type the number of dimes"<<endl;
cin>>n_of_dimes;
cout<<"# of dimes: 4"<<endl;
y = n_of_dimes*0.1;
cout<<"type the number of nickels"<<endl;
cin>>n_of_nickels;
cout<<"# of nickels: 13"<<endl;
z = n_of_nickels*0.05;
cout<<"type the number of pennies"<<endl;
cin>>n_of_pennies;
cout<<"# of pennies: 17"<<endl;
h = n_of_pennies*0.01;
Dollarcent = x+y+z+h;
Dollar = x+y+z+h;
Cent = Dollarcent-Dollar;
cent = Cent*100;
cout<<"The number of the coin is "<<Dollar<<" dollar and "<<cent<<" cent.";
return 1;
}
运行结果是正确的但提交页面上是错的
然后是显示的错误:
Test Failed: 'type the number of quarters 20type the num[115 chars]ent.' != 'the total is 6 dollars and 22 cents'
- type the number of quarters 20type the number of dimes 4type the number of nickels 13type the number of pennies 17the number of the coin is 6 dollar and 22 cent.
+ the total is 6 dollars and 22 cents
:
我不是很理解,麻烦大佬们帮忙看下谢谢