计算销售税和总额

时间:2016-09-14 20:33:17

标签: c++

我现在已经编码了几天并决定进行锻炼。一个计算总共五个项目并计算税收。 在这个特定的练习中,我设法显示了项目的名称和价格,但是,销售税和总额没有显示。我知道这是一个非常基本的问题,我一直试图亲自动手学习,通过反复试验让自己熟悉一点。对于计算部分,任何人都可以找出我所遗漏的内容吗?谢谢你。

#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;

2 个答案:

答案 0 :(得分:2)

我只看到五个价格的cout语句,而不是saletaxgrandtotal,这可以解释它们没有显示。

答案 1 :(得分:2)

它没有显示,因为你从不打印它。

在主要功能的末尾添加这些行,您将看到它。

cout << "Total: " << grandtotal << endl;
cout << "Tax: " << saletax << endl;