標題:
購物系統 (二)
[打印本頁]
作者:
方浩葦
時間:
2024-7-13 09:09
標題:
購物系統 (二)
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢,執行畫面如下圖所示。
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
林少謙
時間:
2024-7-13 16:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string a[]{"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 ",};
int b[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"商品價目表"<<endl;
for(int i=0; i<7; i++)
{
cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
}
cout<<"<8>結帳"<<endl;
re:
cout<<endl;
int x,y,w=-1,sum=0;
re2:
cout<<"請輸入商品代碼:";
cin>>x;
if(x==8)
{
goto out;
}
else if(x>=1&&x<=7)
{
cout<<"請輸入購買數量:";
cin>>y;
sum+=b[x-1]*y;
goto re2;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
out:
cout<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-13 16:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,r=0;
string a[7]={"遙控汽車","飛機模型","足球/t","拼圖/t","玩具槍","可愛玩偶","籃球/t"};
int b[7]={450,550,325,200,660,150,380};
cout<<"玩具店"<<endl<<endl;
cout<<"[價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"("<<i+1<<")"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p<=8&&p>=1){
if(p==8){
goto checkout;
}
else{
cout<<"數量: ";
cin>>q;
r+=b[p-1]*q;
goto re2;
}
}
else{
goto re;
}
checkout:
cout<<endl<<"總共"<<r<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
李唯銘
時間:
2024-7-13 16:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"智能玩具店"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入代碼: ";
cin>>p;
if(p==8){
goto checkout;
}
else if(p>=1 && p<=7){
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}
else
goto re;
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
李偈睿
時間:
2024-7-13 16:14
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"*****智能玩具店*****"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-13 16:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string n[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
cout<<"("<<i+1<<")"<<n[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
goto checkout;
else if(p<=7 && p>=1){
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}
else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
system("pause");
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-13 16:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p, q, sum=0;
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"★☆★智能玩具店★☆★"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}
else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}
else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
高湘庭
時間:
2024-7-14 17:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
while(true){
system("cls");
int p,q,sum=0;
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++){
cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;}
cout<<"<8>"<<"結帳"<<endl;
while(true){
cout<<"請輸入商品代碼"<<endl;
cin>>p;
if(p==8)
break;
else if(p>=1&&p<=7){
cout<<"數量:";
cin>>q;
sum+=price[p-1]*q;}
else{
cout<<"無效的商品代碼,請重新輸入"<<endl;
break;}
}
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2