计算销售税,合计
Calculating sales tax, and total
我已经写了几天代码了,决定做一次练习。一个计算5个项目的总数并计算税费。在这个特殊的练习中,我成功地显示了商品的名称和价格,但是没有显示销售税和总额。我知道这是一个非常基本的问题,我只是试着通过尝试和错误来学习,让自己更熟悉一些。有人能指出我在计算部分遗漏了什么吗?谢谢。
#include <iostream>
using namespace std;
float tax = 0.07;
string item1,item2,item3,item4,item5;
float price1,price2,price3,price4,price5;
int main()
{
cout<<" please enter the name of the first item n";
cin>> item1;
cout<<" please enter the name of second item n";
cin>> item2;
cout<<" plrease enter the name of the third item n";
cin>> item3;
cout<<" please enter the name of the fourth item n";
cin>> item4;
cout<<" please enter the name of the fifth item n";
cin>> item5;
cout<<" please enter the price for the first item n";
cin>> price1;
cout<<" please enter the price for the second item n";
cin>> price2;
cout<<" please enter the price for the third item n";
cin>> price3;
cout<<" please enter the price for the fourth item n";
cin>> price4;
cout<<" please enter the price for the fifth item n";
cin>> price5;
float subtotal = 0;
float saletax = 0;
float grandtotal = 0;
subtotal = price1 + price2 + price3 + price4 + price5;
saletax = subtotal * tax;
grandtotal = subtotal + saletax;
cout<<"my shopping list n";
cout<<"================n";
cout<<item1<<" "<<"$"<<price1 <<endl;
cout<<item2<<" "<<"$"<<price2 <<endl;
cout<<item3<<" "<<"$"<<price3 <<endl;
cout<<item4<<" "<<"$"<<price4 <<endl;
cout<<item5<<" "<<"$"<<price5 <<endl;
没有显示,因为您从未打印它。
将这一行添加到main函数的末尾,您将看到它。
cout << "Total: " << grandtotal << endl;
cout << "Tax: " << saletax << endl;
我只看到了五个价格的cout
语句,没有看到saletax
或grandtotal
,这就解释了为什么没有显示它们。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 递归函数计算序列中的平方和(并输出过程)
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的字符计数代码计算错误.为什么
- 在计算中使用二的幂有多有利可图
- 如何计算文件中的"columns"数?
- 计算排序向量的向量中唯一值的计数
- 如何使用 std::累积在 C++ 中计算总和立方体
- 使用Qt C++计算类似Git的SHA1哈希
- OpenCV C++.快速计算混淆矩阵
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- C++如何计算用户输入的数字中的偶数位数
- 如何计算数据类型的范围,例如int
- 类似枚举的计算常量
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 计算缩放多边形的比例,得到给定的多边形面积
- 在C++中如何在没有pow的情况下进行基础计算
- 计算平均值,不包括上次得分
- 计算销售税,合计