標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2020-12-5 20:29
標題:
購物系統 (二)
本帖最後由 tonyh 於 2020-12-5 20:46 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢,執行畫面如下圖所示。
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃子倢
時間:
2020-12-5 20:54
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t, q, total=0;
string n[5]={"玩具車","熊玩偶","羽毛球","乒乓球","玩具槍"};
int p[5]={450,300,30,10,600};
cout<<"☆智能玩具店☆"<<endl<<endl;
cout<<"商品價目表"<<endl<<endl;
for(int i=0; i<5; i++)
{
cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
}
cout<<"請輸入8來結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼:";
cin>>t;
if(t==8)
{
goto checkout;
}else if(t>0 && t<8)
{
cout<<"數量:";
cin>>q;
total+=p[t-1]*q;
goto re;
}else
{
goto re ;
}
checkout:
cout<<endl<<"總共"<<total<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
俞成章
時間:
2020-12-5 20: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;
}
複製代碼
作者:
林鼎傑
時間:
2020-12-5 20:59
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"黃色飛機 ","金正恩模型","笑氣 ","手槍 ","充氣玩偶",
"籃鳥 ","核彈 ","雄商飛彈"};
int price[]={1233,666,999,2150,2999,799,9500,4987};
cout<<"☆★☆畸形軍火庫☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<8; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(9)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==9)
{
goto checkout;
}else if(p>=1 && p<=8)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
許洧熏
時間:
2020-12-5 21:00
#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;
}
複製代碼
作者:
余柏緯
時間:
2020-12-5 21:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李柏穎
時間:
2020-12-5 21:00
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int c, d, sum=0;
int a[7]={450,550,325,200,660,150,380};
string b[7]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"<"<<i+1<<">"<<b[i]<<"\t"<<a[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl;
cout<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>c;
if(c==8)
goto checkout;
else if(c>=1 && c<=7)
{
cout<<"請輸入商品數量: ";
cin>>d;
sum=sum+a[c-1]*d;
goto re2;
}
else
goto re;
checkout:
cout<<"總共"<<sum<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
呂尚霖
時間:
2020-12-5 21:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[]={"火箭炮彈","防護盾槍","核彈 ","手槍 ","特斯拉 ","警察手銬","步槍 "};
int price[]={5000,59487,999999,1,660000,15,8787};
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王秉鈞
時間:
2020-12-5 21:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[6]={"雪莉(玩偶)","黑雞 鐵鏟 氫氣氣球","炸彈 ","鉛筆模型 ","明太子(炸彈) ","史派克 "};
int price[6]={0,658,95110,45454,78945,9214};
cout<<"史派克丸劇墊"<<endl<<endl;
cout<<"[商品架木表]"<<endl;
for(int i=0;i<6;i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼:";
cin>>p;
if (p==8)
{
goto checkout;
}else if(p>=1&& p<=7)
{
cout<<"數量:";
cin>>q;
sum+price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
朱奕祐
時間:
2020-12-9 19:11
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王宇崴
時間:
2020-12-12 19:19
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[]={"遙控汽車","飛機模型","足球模","拼圖飛機","玩具槍 ","可愛玩偶","籃球 "};
int price[]={45000,55000,32500,20000,66000,15000,38000};
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王首二
時間:
2020-12-12 19:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[]={"笑氣 ","雄商飛彈","核彈 ","拼圖飛機","羽毛球","乒乓球","籃球 "};
int price[]={45000,55000,32500,20000,66000,15000,38000};
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
作者:
王首二
時間:
2020-12-12 19:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[]={"笑氣 ","雄商飛彈","核彈 ","拼圖飛機","羽毛球","乒乓球","籃球 "};
int price[]={45000,55000,32500,20000,66000,15000,38000};
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;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2