標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2017-3-4 13:52
標題:
購物系統 (二)
本帖最後由 tonyh 於 2019-3-2 10:18 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.
#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;
}
複製代碼
作者:
黃宥鈞
時間:
2017-3-4 14:25
#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 pay;
}else if(p>0 && p<8)
{
cout<<"數量:";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
pay:
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
許紘誌
時間:
2017-3-4 14:32
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
cout<<"☆★☆智能雜貨店 ☆★☆"<<endl<<endl;
string name[6]={"礦泉水","柳橙汁","可口可樂-小","可口可樂-中","可口可樂-大","結帳"};
int price[5]={10,15,20,25,30};
cout<<"商品價目表"<<endl;
for(int i=0; i<5; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(6)"<<name[5]<<endl;
re2:
cout<<"請輸入商品代碼:";
cin>>p;
if(p==6)
{
goto checkout;
}else if(p>=1 && p<=5)
{
cout<<"數量:";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2017-3-4 14:34
本帖最後由 洪榜蔓 於 2017-3-4 15:11 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"iPhone1","iPhone2","iPhone3","iPhone4","iPhone5","iPhone6","iPhone7"};
int price[]={19999,29999,30000,32000,34000,38000,40000};
cout<<"#iPhone專賣店#"<<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");
return 0;
}
複製代碼
作者:
吳承勳
時間:
2017-3-4 14:35
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"遙控器車","飛機模型","籃球 "};
int price[]={450,550,300};
cout<<"智能玩具店"<<endl<<endl;
cout<<"[商品價目]"<<endl;
for(int i=0; i<3; 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<=1)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蕭澧邦
時間:
2017-3-4 14:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
replay:
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;
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 replay;
}
checkout:
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
goto replay;
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2017-3-4 14:42
#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<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2017-3-7 18:52
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"Basketball "," Toy car "," Computer "," Books "," Television"," Pencil "};
int price[]={450,550,325,200,660,150};
cout<<" 智能玩具店"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<6; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"NT"<<endl;
cout<<"(7)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==7)
{
goto checkout;
}else if(p>=1 && p<=6)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"NT!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2