| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 708 人关注过本帖
标题:Coin Counter 问题
只看楼主 加入收藏
Vivina
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-6-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
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
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:20 
为什么你连提示文字都不肯依照题目要求

程序代码:
#include <iostream>
using namespace std;

int main( void )
{
    cout << "Please enter the number of coins:\n";

    int n_of_quarters;
    cout << "# of quarters: ";
    cin >> n_of_quarters;

    int n_of_dimes;    
    cout << "# of dimes: ";
    cin >> n_of_dimes;

    int n_of_nickels;
    cout << "# of nickels: ";
    cin>>n_of_nickels;

    int n_of_pennies;
    cout << "# of pennies: ";
    cin>>n_of_pennies;

    int cents = n_of_quarters*25 + n_of_dimes*10 + n_of_nickels*5 + n_of_pennies*1;
    cout << "The total is " << cents/100 << " dollars and " << cents%100 << " cents\n";

    return 0;
}
2022-06-06 08:48
快速回复:Coin Counter 问题
数据加载中...
 
   



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

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