標題:
購物系統 (三)
[打印本頁]
作者:
tonyh
時間:
2013-7-6 15:00
標題:
購物系統 (三)
本帖最後由 tonyh 於 2013-7-6 15:01 編輯
再次改寫購物系統之程式碼, 將抓取商品代碼與數量的動作分開來.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={450,550,325,200,660,150,380};
int p,q,sum=0;
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
cout<<"(1)遙控汽車\t450元"<<endl;
cout<<"(2)飛機模型\t550元"<<endl;
cout<<"(3)足球\t\t325元"<<endl;
cout<<"(4)拼圖\t\t200元"<<endl;
cout<<"(5)玩具槍\t660元"<<endl;
cout<<"(6)可愛玩偶\t150元"<<endl;
cout<<"(7)籃球\t\t380元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張瀚仁
時間:
2013-7-6 15:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={1240,136,2584,251,987,654};
int a,b,sum=0,pay,money;
cout<<"***歡樂屋***"<<endl;
cout<<"商品價目表"<<endl;
cout<<"(1)一日喪命散\t\t1240元"<<endl;
cout<<"(2)含笑半步癲\t\t136元"<<endl;
cout<<"(3)地獄一日遊\t\t2584元"<<endl;
cout<<"(4)地獄拔舌體驗卷\t251元"<<endl;
cout<<"(5)爬劍山體驗卷\t\t987元"<<endl;
cout<<"(6)棺材訂做\t\t654元"<<endl;
cout<<"死亡一概不負責,消費滿5000送棺材乙個!!(限量 鍍金市價10000元)"<<endl;
cout<<"選購完時代號都輸入8即可進入結帳頁"<<endl;
start:
cout<<"請輸入商品代號:"<<endl;
cin>>a;
if(a==8)
{
goto end;
}
cout<<"請輸入數量:"<<endl;
cin>>b;
if(a>=1 && a<=7 && b>0)
{
sum=sum+price[a-1]*b;
goto start;
}else
{
cout<<"輸入錯誤"<<endl;
goto start
}
end:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
if(sum>=5000)
{
cout<<"由於消費滿5000,贈送鍍金棺材乙個!!"<<endl;
}
cout<<"請輸入付了多少錢: ";
cin>>pay;
money=pay-sum;
if(money==0)
{
cout<<"錢剛剛好! 請慢走!"<<endl;
}
if(money<0)
{
cout<<"錢不夠! 還欠"<<-money<<endl;
}
if(money>0)
{
cout<<"總共需要找客人"<<money<<"元";
if(money>=500)
{
cout<<"500元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"100元鈔票"<<money/100<<"張"<<endl;
money=money%100;
}
if(money>=50)
{
cout<<"50元硬幣"<<money/50<<"枚"<<endl;
money=money%50;
}
if(money>=10)
{
cout<<"10元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
}
if(money>=5)
{
cout<<"5元硬幣"<<money/5<<"枚"<<endl;
money=money%5;
}
if(money>=1)
{
cout<<"1元硬幣"<<money/1<<"枚"<<endl;
money=money%1;
}
}
system("pause");
return 0;
}
複製代碼
作者:
黃崇維
時間:
2013-7-6 15:15
本帖最後由 黃崇維 於 2013-7-6 15:18 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={10000,12000,12300,12340,12345,123456,1234567};
int p, q, money, pay, sum=0;
cout<<"崇維智能電腦房屋店"<<endl<<endl;
cout<<"[電腦價目表]"<<endl;
cout<<"(1)一星級電腦\t10000元"<<endl;
cout<<"(2)二星級電腦\t12000元"<<endl;
cout<<"(3)三星級電腦\t12300元"<<endl;
cout<<"(4)四星級電腦\t12340元"<<endl;
cout<<"(5)五星級電腦\t12345元"<<endl;
cout<<"(6)六星級電腦\t123456元"<<endl;
cout<<"(7)七星級電腦\t1234567元"<<endl;
cout<<"(8)結帳"<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"請輸入數量:";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉泳鱔
時間:
2013-7-6 15:16
本帖最後由 劉泳鱔 於 2013-7-6 15:19 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={450,550,325,200,660,150,380};
int p,q,sum=0;
cout<<"$$超能商店$$"<<endl;
cout<<"[商品價格]"<<endl;
cout<<"(1)屎一斤\t550元"<<endl;
cout<<"(2)坦克模型\t550元"<<endl;
cout<<"(3)魔球\t\t325元"<<endl;
cout<<"(4)藍圖\t\t200元"<<endl;
cout<<"(5)機關槍\t660元"<<endl;
cout<<"(6)驚悚玩偶\t150元"<<endl;
cout<<"(7)保齡球\t\t380元"<<endl;
cout<<"[使用說明]"<<endl;
cout<<"依序輸入想購買的商品與數量,如籃球兩顆請輸入'7 2'"<<endl;
cout<<"選購完畢時輸入'8 8'進入結帳頁"<<endl<<endl;
start:
cout<<"在此輸入: ";
cin>>p;
if(p==8)
{
goto checkout;
}
else if(p>=1 && p<=7 && q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else if(p==8 && q==8)
{
goto checkout;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃柏維
時間:
2013-7-6 15:17
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={450,550,325,200,660,150,380};
int p,q,pay,money,sum=0;
cout<<"***智能玩具店***"<<endl;
cout<<"**商品價目表**"<<endl;
cout<<"(1)遙控汽車\t450元"<<endl;
cout<<"(2)飛機模型\t550元"<<endl;
cout<<"(3)足球\t\t325元"<<endl;
cout<<"(4)拼圖\t\t200元"<<endl;
cout<<"(5)玩具槍\t660元"<<endl;
cout<<"(6)可愛玩偶\t150元"<<endl;
cout<<"(7)籃球\t\t380元"<<endl;
cout<<"(8)結帳"<<endl;
cout<<"$$請選擇你要的商品$$"<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"請輸入商品數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤"<<endl;
goto start;
}
}
else
{
cout<<"輸入錯誤"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭凡瑛
時間:
2013-7-6 15:23
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={300,250,150,600,1000};
int p,q,sum=0;
cout<<"書店"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
cout<<"(1)小說\t\t300元"<<endl;
cout<<"(2)漫畫\t\t250元"<<endl;
cout<<"(3)雜誌\t\t150元"<<endl;
cout<<"(4)字典\t\t600元"<<endl;
cout<<"(5)百科全書\t1000元"<<endl;
cout<<"(6)結帳"<<endl<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==6)
{
goto checkout;
}else if(p>=1 && p<=5)
{
cout<<"請輸入數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤"<<endl;
goto start;
}
}else
{
cout<<"輸入錯誤"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system ("pause");
return 0;
}
複製代碼
作者:
長逸
時間:
2013-7-6 15:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={450,550,325,200,660,150,380};
int p,q,sum=0;
cout<<"槍的店"<<endl<<endl;
cout<<"[殺手表]"<<endl;
cout<<"(1)黑白雙煞\t123元"<<endl;
cout<<"(2)金蠍雙擊\t132元"<<endl;
cout<<"(3)準雷\t213元"<<endl;
cout<<"(4)赤玉魔龍\t\t231元"<<endl;
cout<<"(5)紅白雙心\t312元"<<endl;
cout<<"(6)碎骨銀狼\t321元"<<endl;
cout<<"(7)藍寶槍\t\t123元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蘇昱安
時間:
2013-7-6 15:48
本帖最後由 蘇昱安 於 2013-7-6 15:50 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={450,550,325,200,660,150,380};
int p,q,sum=0;
cout<<"智能玩具店"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
cout<<"(1)遙控汽車\t450元"<<endl;
cout<<"(2)飛機模型\t550元"<<endl;
cout<<"(3)足球\t\t325元"<<endl;
cout<<"(4遙控飛機\t\t200元"<<endl;
cout<<"(5)玩具槍\t660元"<<endl;
cout<<"(6)可愛玩偶\t150元"<<endl;
cout<<"(7)籃球\t\t380元"<<endl<<endl;
cout<<"(8)結帳"<<endl<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林以諾
時間:
2013-7-12 19:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={10000,5000,50000,4444,10,1744,55,10000};
int h, q, pay, money,sum=0;
cout<<"以諾豪華九星級飯店"<<endl;
cout<<"[飯店房間價目表]"<<endl;
cout<<"(1)四人套房\t10000元"<<endl;
cout<<"(2)兩人套房\t5000元"<<endl;
cout<<"(3)七人小木屋\t50000元"<<endl;
cout<<"(4)孤單一人房\t4444元"<<endl;
cout<<"(5)百人總統房\t10元"<<endl;
cout<<"(6)安靈病房\t1744元"<<endl;
cout<<"(7)太平間地下房\t55元"<<endl;
cout<<"(8)跟泳鱔一夜情套房\t1元"<<endl;
cout<<"[付費說明]"<<endl;
cout<<"把要住的房間代號輸入後,再輸入要買幾間"<<endl;
cout<<"購買完請輸入9前往結帳"<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>h;
if(h==9)
{
goto checkout;
}
else if(h>=1 && h<=8)
{
cout<<"請輸入購買數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[h-1]*q;
goto start;
}
else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
}
else
{
cout<<"什麼年紀了還會輸入錯誤!!"<<endl;
goto start;
}
checkout:
cout<<"總共是"<<sum<<"元"<<endl;
cout<<"請輸入客人付了多少錢: ";
cin>>pay;
money=pay-sum;
if(money==0)
{
cout<<"錢剛剛好! 請慢走!"<<endl;
}
if(money<0)
{
cout<<"錢不夠! 還少"<<-money<<endl;
}
if(money>0)
{
cout<<"總共需要找客人"<<money<<"元";
if(money>=500)
{
cout<<"500元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"100元鈔票"<<money/100<<"張"<<endl;
money=money%100;
}
if(money>=50)
{
cout<<"50元硬幣"<<money/50<<"枚"<<endl;
money=money%50;
}
if(money>=10)
{
cout<<"10元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
}
}
system("pause");
return 0;
}
複製代碼
作者:
許逸群
時間:
2013-7-12 19:53
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[]={450,550,1000,200,660,150,380};
int p,q,sum=0;
cout<<"☆★☆21世紀ㄟ店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
cout<<"(1)空氣\t450元"<<endl;
cout<<"(2)石油\t550元"<<endl;
cout<<"(3)行星\t1000元"<<endl;
cout<<"(4)水\t200元"<<endl;
cout<<"(5)陽光\t660元"<<endl;
cout<<"(6)黃金\t10000元"<<endl;
cout<<"(7)泥土\t380元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
start:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
goto checkout;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
if(q>0)
{
sum=sum+price[p-1]*q;
goto start;
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
}else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2