C++ 如何使用循环和数组合计所有输入的项目代码(带有相应的值)?

C++ 如何使用循环和数组合计所有输入的项目代码(带有相应的值)?,c++,C++,献给所有程序员、爱好者和专业人士!我是C++编程新手。我只是想问一下,在我的“采购项目”计划中,我将如何完成这项任务。用户正在输入一个项目代码,该项目代码具有相应的值,并且还输入了该项目的数量。如果用户说是,程序将循环并需要添加用户输入的所有以前的值,则程序将询问“您是否想购买其他物品”。我的问题是我如何循环这个和用户输入的所有项目的总价值。我们不使用fstream.h p104和p103是项目代码 #include<iostream.h> #include<stdio.h&g

献给所有程序员、爱好者和专业人士!我是C++编程新手。我只是想问一下,在我的“采购项目”计划中,我将如何完成这项任务。用户正在输入一个项目代码,该项目代码具有相应的值,并且还输入了该项目的数量。如果用户说是,程序将循环并需要添加用户输入的所有以前的值,则程序将询问“您是否想购买其他物品”。我的问题是我如何循环这个和用户输入的所有项目的总价值。我们不使用fstream.h

p104和p103是项目代码

#include<iostream.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
main()
{
clrscr();
int p104 = 25, order, total = 0, subtotal, p103 = 22,itemcode, quantity, back;
do{
cout<<"Enter Item Code: ";
cin>>itemcode;
cout<<"\nEnter number of quantity: ";
cin>>quantity;
cout<<subtotal;
total=total+subtotal;
cout<<"\n"<<total;
cout<<"\nWould you like to purchase other item? [Y]-yes?";
cin>>back;
  }
while(back=='Y'||back=='y');
getch();
return 0;
}
#包括
#包括
#包括
#包括
main()
{
clrsc();
int p104=25,订单,总计=0,小计,p103=22,项目代码,数量,背面;
做{
库蒂码;
能力;
不能在
cin>>back\u;
之后使用getchar()获取换行符,并根据条件计算
小计

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<conio.h>
using namespace std;
main()
{
//clrscr();
char back_;
int p104 = 25, order, total = 0, subtotal =0, p103 = 22,itemcode, quantity;
do{
cout<<"Enter Item Code: ";
cin>>itemcode;
cout<<"\nEnter number of quantity: ";
cin>>quantity;
//cout<<subtotal;
if (itemcode == 104){
    subtotal = quantity * p104;
}else if (itemcode == 103){
    subtotal = quantity * p103;
}
total=total+subtotal;
subtotal =0;
cout<<"\n"<<total;
cout<<"\nWould you like to purchase other item? [Y]-yes?";
cin>>back_;
getchar();
  }
while(back_=='Y'||back_=='y');
return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
main()
{
//clrsc();
炭背;
int p104=25,订单,总计=0,小计=0,p103=22,项目代码,数量;
做{
库蒂码;
能力;

//谢谢David Weston先生!你帮了我很多忙。:DMr.Weston我有我的代码。我按照你告诉我的做了添加总输入的项目代码。我还有一个问题,先生,你能找到吗?我的问题是我不能循环我的代码。我想我的do while语句有问题。我在我的帐户上发布了我的新问题。谢谢你u、 检查你问题的答案。这对你有什么帮助?@JanNavasca