標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2019-12-20 19:11
標題:
購物系統 (二)
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢,執行畫面如下圖所示。
#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;
}
複製代碼
作者:
林政瑜
時間:
2019-12-20 19:42
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int p,q,sum=0;
string name[]={"步槍 ","機關槍","狙擊槍","雷射槍","反坦克步槍","火箭炮","手槍 "};
int price[]={30,45,60,50,90,75,10};
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:
system("pause");
return 0;
}
複製代碼
作者:
李宇澤
時間:
2019-12-20 19:43
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int a,b,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>>a;
if(a==8)
{
goto checkout;
}else if(a>=1 && a<=7)
{
cout<<"數量: ";
cin>>b;
sum+=price[a-1]*b;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
黃辰昊
時間:
2019-12-20 19:44
#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;
while(true)
{
cout<<"請輸入商品編號: ";
cin>>p;
if(p==8)
break;
cout<<"請問要買幾個: ";
cin>>q;
sum+=price[p]*q;
}
cout<<sum<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
余有晉
時間:
2019-12-20 19:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"布加迪凱龍,BMW M4,東迎戰神GTR,麥拉倫,保時捷,瑪莎拉蒂,藍寶堅尼"};
int price[]={455100000,55000052,32045500,20000045,66000254,15005460,38678460};
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;
}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;
}
複製代碼
作者:
黃宥華
時間:
2019-12-20 19:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
Q:
system("cls");
string com[8]={"紙10張","袋子","洋芋片","奶茶","書套","鍵盤","滑鼠","漫畫4本"};
int mon[]={5,10,25,39,80,499,990,1499};
cout<<"智能雜貨店 商品名稱"<<endl<<endl;
cout<<"滿5000元享9折優惠!"<<endl<<endl;
cout<<"編號"<<"\t"<<"名稱"<<"\t"<<"\t"<<"價格"<<endl;
for(int i=0; i<8; i++)
{
cout<<"("<<i+1<<")"<<"\t"<<com[i]<<"\t"<<"\t"<<mon[i]<<"元"<<endl;
}
cout<<"(9)"<<"\t"<<"結帳"<<"\t"<<endl;
re:
int much[]={0,0,0,0,0,0,0,0};
int mone[]={0,0,0,0,0,0,0,0};
float y=0;
int c=0;
while(1)
{
int x=0,w=0;
cout<<"請輸入商品編號:";
cin>>x;
if(x==9)
break;
else
cout<<"請輸入數量:";
cin>>w;
if(x<=8 && x>=1){
y+=mon[x-1]*w;
much[x-1]+=w;
mone[x-1]+=mon[x-1]*w;
}else{
cout<<"輸入錯誤"<<endl;
}
}
for(int i=0; i<8; i++)
cout<<"("<<i+1<<")"<<"\t"<<com[i]<<"\t"<<"\t"<<much[i]<<"個"<<" 小計"<<"\t"<<mone[i]<<"元"<<endl;
if(y>=5000){
cout<<"因滿5000元所以享九折優惠"<<endl;
y=y*0.9;
}
cout<<"一共"<<y<<"元"<<endl;
cout<<"1 重新選購 2 確定無誤:";
cin>>c;
if(c==2){
int pay,money;
cout<<"付了多少錢: ";
cin>>pay;
money=pay-y;
if(money>=0)
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
cout<<"謝謝惠顧"<<endl;
}
else{
cout<<"錢不夠 還差"<<y-pay<<"元"<<endl;
}
}
else if(c==1){
goto re;
}
else
cout<<"輸入錯誤"<<endl;
system("pause");
goto Q;
return 0;
}
複製代碼
作者:
孫嘉駿
時間:
2019-12-20 19:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int j,f,sum=0;
string name[]={"遙控器車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={2000,2000,3250,20,6600,150,3800};
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>>j;
if(j==8)
{
goto checkout;
}else if(j>=1 && j<=7)
{
cout<<"數量: ";
cin>>f;
sum+=price[j-1]*f;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
蔡忻霓
時間:
2019-12-20 19:53
#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;
}
複製代碼
作者:
陳宥穎
時間:
2019-12-20 19:54
#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;
}
複製代碼
作者:
董宸佑
時間:
2019-12-20 19:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string c[]={"遙控汽車\t",
"飛機模型\t",
"足球\t ",
"拼圖\t ",
"玩具槍\t",
"可愛玩偶\t",
"籃球\t "};
int n[]={450,550,325,200,660,150,380};
cout<<"▲▲▲智障玩具店▲▲▲"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"<"<<i+1<<">"<<c[i]<<n[i]<<"元"<<endl;
cout<<endl;
re:
cout<<"請輸入商品代碼 (若想結帳,請輸入8) : ";
cin>>p;
if(p==8)
goto out;
else if(p>=1 && p<=7)
{
cout<<"數量:";
cin>>q;
sum+=n[p-1]*q;
goto re;
}
else
{
goto re;
}
out:
cout<<endl<<"總共"<<sum<<"元!!!!!!!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2