標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2015-3-14 10:28
標題:
購物系統 (二)
本帖最後由 tonyh 於 2015-3-14 11:57 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.
[attach]1168[/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};
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;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪振庭
時間:
2015-3-14 11:58
#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};
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;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李大全
時間:
2015-3-14 12:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[7]={"3","5","6 ",
"2 ","1","手機","按摩棒 "};
int price[7]={45,55,35,20,22,22000,380};
cout<<"a"<<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;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李知易
時間:
2015-3-14 12:08
#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;
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;
}
else
{
cout<<"輸入錯誤!"<<endl;
}
goto re;
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
梁和雋
時間:
2015-3-14 12:08
本帖最後由 梁和雋 於 2015-3-21 11:12 編輯
#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;
}
goto re;
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
謝瀞儀
時間:
2015-3-14 14:04
本帖最後由 謝瀞儀 於 2015-3-14 14:27 編輯
#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};
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;
}
else
{
cout<<"奧客去死辣!本店將會詛咒你的餘生(甩門)"<<endl;
}
goto re;
checkout:
cout<<"共"<<sum<<"萬元"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2