as12350991 2020-10-13 22:19 采纳率: 50%
浏览 58
已采纳

C++新手,正在做题,有些题做出来经过调试错误比较多。

Program 2: Restaurant Bill

Overview

Write a program to split a restaurant bill evenly between a given number of people.

Directions

Write a tool for calculating and splitting restaurant bills. Your program should ask the user how much the bill is before tax, what percentage the sales tax is, what percentage tip they would like to add, and how many people are splitting the bill. Calculate the final cost of the bill by first adding the sales tax, then adding the tip. Find the cost per person by dividing the bill by the number provided. Print each value to the console: the bill before tax, the bill after tax, the bill after tip, and the bill per person.

The listing below shows an example of what the input and output for this program might look like. Input by the user is listed in blue.

How much is the bill? 57.75
How much is the tax (%)? 5
How much is the tip (%)? 20
How many people are paying? 3

Bill before tax: 57.75
Bill after tax: 60.64
Bill after tip: 72.76
Bill per person: 24.26

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-10-13 23:47
    关注
    #include <iostream>
    using namespace std;
    int main()
    {
    float bill, tax, tip;
    int n;
    cout << "How much is the bill?";
    cin >> bill;
    cout << "How much is the tax (%)?" << endl;
    cin >> tax;
    cout << "How much is the tip (%)?" << endl;
    cin >> tip;
    cout << "How many people are paying?" << endl;
    cin >> n;
    cout << "Bill before tax: " << bill << endl;
    cout << "Bill after tax: " << bill * (1 + tax / 100.0) << endl;
    cout << "Bill after tip: " << ( bill * (1 + tax / 100.0)) * (1 + tip / 100.0) << endl;
    cout << "Bill per person: " <<  ( bill * (1 + tax / 100.0)) * (1 + tip / 100.0)  / (float)n << endl;
    return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用