標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2015-10-2 20:03
標題:
購物系統 (二)
本帖最後由 tonyh 於 2015-10-2 21:22 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.
[attach]1415[/attach]
#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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
goto re;
}else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
沈子耕
時間:
2015-10-2 20:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int num=0,lab,q;
string tag[9]={"俠盜列車手5 ","決勝時刻:黑色行動3","虹彩六號:圍突行動 ",
"minecraft ","星際大戰:戰場前線 ","正當防衛3 ",
"湯姆克蘭西:末日邊界","潛龍諜影:幻痛 "};
int price[8]={2250,2250,1790,990,2500,1900,1500,2200};
cout<<"\t※※※子耕電玩專賣店※※※"<<endl<<"本店商品保證便宜^_^"<<endl<<endl;
cout<<"[商品一覽表]"<<endl;
for(int i=0; i<8; i++){
cout<<"<"<<i+1<<">"<<tag[i]<<"\t\t"<<price[i]<<"元"<<endl;
}
cout<<"<9>結帳去"<<"\t\t"<<endl<<endl;
cout<<"[優惠方案]\t本店滿5000元及立刻打九折"<<endl<<endl;
A:
cout<<"請輸入商品代碼: ";
cin>>lab;
if(lab==9)
goto B;
cout<<"數量: ";
cin>>q;
num+=price[lab-1]*q;
goto A;
B:
cout<<"共"<<num<<"元"<<endl;;
system("pause");
return 0;
}
複製代碼
作者:
黃璽安
時間:
2015-10-2 21:19
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
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;
int i;
cout<<"請輸入商品代碼:"<<endl;
cin>>i;
if(i==8)
{
goto checkout;
}
system("pause");
return 0;
}
複製代碼
作者:
林侑成
時間:
2015-10-3 20:38
#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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
goto re;
}else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾挺桂
時間:
2015-10-16 20:16
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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
goto re;
}else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
複製代碼
作者:
陳思惟
時間:
2015-10-23 20:12
#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;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
sum+=price[p-1]*q;
goto re;
}else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2