标题:Coin Counter 问题
取消只看楼主
Vivina
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-6-5
结帖率:0
已结贴  问题点数:20 回复次数:0 
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
 :

我不是很理解,麻烦大佬们帮忙看下谢谢
搜索更多相关主题的帖子: and int cout number the 
2022-06-05 13:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-509263-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017408 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved