標題:
購物系統 (三)
[打印本頁]
作者:
tonyh
時間:
2015-3-21 10:15
標題:
購物系統 (三)
本帖最後由 tonyh 於 2015-3-21 11:41 編輯
新增 "購物清單" 功能, 使結帳時能不只計算出價錢, 還能列出細目.
參考執行畫面如下:
[attach]1181[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[7]={"遙控汽車","飛機模型","足球 ",
"拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[7]={450,550,325,200,660,150,380};
int qty[7]={0,0,0,0,0,0,0};
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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
qty[p-1]+=q;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"[購物清單]"<<endl;
cout<<"-----------------------------"<<endl;
for(int i=0; i<7; i++)
{
if(qty[i]!=0)
cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
}
cout<<"-----------------------------"<<endl;
cout<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪振庭
時間:
2015-3-21 11:25
本帖最後由 洪振庭 於 2015-3-22 11:43 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[7]={"速效跳課糖","米你毛毛球","無頭帽","金斯雀奶油","攜帶型沼澤","假魔杖","伸縮耳"};
int price[7]={90,150,74,3,80,1,4};
int qty[7]={0,0,0,0,0,0,0};
cout<<"****衛氏巫師法寶店****"<<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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
qty[p-1]+=q;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"[魔法清單]"<<endl;
cout<<"-----------------------------"<<endl;
for(int i=0; i<7; i++)
{
if(qty[i]!=0)
cout<<name[i]<<"\t"<<price[i]<<"加隆 * "<<qty[i]<<"個"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
李知易
時間:
2015-3-21 11:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[5]={"砍頭優惠卷","特效搖頭丸","自殺體驗卷","被打免費票","舒柔鼻涕蟲",};
int price[5]={99111,458645,14000,99999,100000};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
int qty[5]={0,0,0,0,0};
for(int i=0; i<5; 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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
qty[p-1]+=q;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"噁心清單"<<endl;
cout<<"----------------------------------"<<endl;
for (int i=0;i<5;i++)
{
if(qty[i]!=0)
cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
}
cout<<"----------------------------------"<<endl;
cout<<"總共"<<sum<<"元!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
謝瀞儀
時間:
2015-3-21 11:40
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int thing, number,sum=0;
string name[21]={"V家七宗罪系列(包含序號2~9)",
"湯匙(齒輪) ",
"酒杯 ",
"劍 ",
"金鑰匙 ",
"人偶 ",
"四面鏡 ",
"禍世之剪 ",
"上了發條的搖籃曲 ",
"白癡藥水 ",
"生鏽的齒輪人偶 ",
"受詛咒之雙刃(附皮革套) ",
"跳針的古老大鐘 ",
"失憶藥丸 ",
"座敷童子的靈棺 ",
"淌血的附喪神人偶 ",
"會咬人的蜘蛛玩偶 ",
"梅杜莎的頭顱 ",
"巫婆熬藥的大鍋 ",
"活生生殭屍殺人魔/吸血鬼 "};
long money[21]={1200,70,80,80,100,120,150,100,350,
70,80,20,1300,130,700,130,120,500,1000,10000};
int qty[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
cout<<"XXX崩壞/中二玩具精品店XXX"<<endl;
cout<<"這裡的壞掉商品包山包海,應有盡有,等你來搜刮!"<<endl;
cout<<"本店絕對沒有惡意哄抬價格,也絕對沒有低價購入,高價賣出的不良嗜好,敬請安心"<<endl;
cout<<"對於購買商品的問題,出事本店一概不負責"<<endl;
cout<<"--------------------------------------------------------------------------"<<endl;
int i=0;
while(i<20)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"萬元"<<endl;
i++;
}
cout<<"(21)結帳"<<endl;
re:
cout<<"請輸入商品代號: "<<endl;
cin>>thing;
if(thing==21)
{
goto checkout;
}
else if(thing>0 && thing<21)
{
cout<<"數量: "<<endl;
cin>>number;
if(number<=0)
{
cout<<"奧客去死辣!本店將會詛咒你的餘生(甩門)"<<endl;
goto re;
}
sum+=money[thing-1]*number;
qty[thing-1]+=number;
}
else
{
cout<<"奧客去死辣!本店將會詛咒你的餘生(甩門)"<<endl;
}
goto re;
checkout:
cout<<endl<<"中二精品購物清單"<<"\a"<<endl;
cout<<"------------------------------"<<"\n";
for(int i=0;i<21;i++)
{
if(qty[i]!=0)
{
cout<<name[i]<<"\t"<<money[i]<<"元 * "<<qty[i]<<"個"<<endl;
}
}
cout<<"------------------------------"<<"\n";
cout<<"共"<<sum<<"萬元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
梁和雋
時間:
2015-3-21 11:43
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[5]={"CAD ","NERvGear","蘿球 ","密斯提斯","吉太 "};
int price[5]={10000,20000,20000,10000,10000};
cout<<"<?<?<?<<動漫道具店>>?>?>?>"<<endl;
cout<<"<?<?<?<<商品價目表>>?>?>?>"<<endl;
for(int i=0; i<5; i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(6)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==6)
goto checkout;
else if(p>=1 && p<=5)
{
cout<<"數量: ";
cin>>q;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
checkout:
qty[p-1]+=q;
cout<<"---------------------"<<endl;
for(int i=0;i<7;i++)
{
if(qty[i]>0)
cout<<name[i]<<"\t"<<price[i]<<"元"<<qty[i]<<"個"<<endl;
}
cout<<"---------------------"<<endl;
goto re;
cheakout;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2