求一道C++编程题目

2025-01-08 09:15:50
推荐回答(1个)
回答1:

#include"iostream"
using namespace std;
static int weight=0;
void buy()
{
int in_temp;
cout<<"买入重量: ";
cin>>in_temp;
weight+=in_temp;
}
void sell()
{
int out_temp;
cout<<"卖出重量: ";
cin>>out_temp;
weight-=out_temp;
}
void main()
{
char ch;
while(1)
{
cout<<" 1.买入货物重量"< cout<<" 2.卖出货物重量"< cout<<" 3.剩余货物重量"< cout<<" 0.退出"< cout<<"请选择:";
cin>>ch;
switch(ch)
{
case'1':{buy(); break;};
case'2':{sell();break;};
case'3':{cout<<"剩余重量为: "< case'0':exit(1);
}
}
}