我已经编了几天,现在决定开展一项练习。一个计算五个项目的总数并计算税额。 在这个特别的练习中,我已经设法显示物品的名称和价格,但是销售税和总额没有被显示出来。我知道这是一个非常基本的问题,我一直在努力学习,通过反复试验熟悉我自己。就计算部分而言,任何人都可以确定我错过了什么?感谢提前。计算销售税和总计
#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;
究竟是什么问题?你是否得到错误的输出?一个错误? – Mureinik
你没有复制你所有的'main()',所以它不可能解释缺失部分的问题。 – drescherjm
我没有收到任何错误。只是它没有给我总数。因此,当我得到五个物品及其价格时,价格将出现在名称旁边,但不是总计,也不是销售税。 – ReMaKe