標題:
[隨堂測驗] 購物系統 (四)
[打印本頁]
作者:
方浩葦
時間:
2024-7-13 09:10
標題:
[隨堂測驗] 購物系統 (四)
新增 "1-正確無誤 2-重新選購" 的選單,
讓使用者在準備結帳時還能反悔,譬如錢帶不夠。
確定結帳後,銜接自動找零系統。
本帖隱藏的內容需要回復才可以瀏覽
作者:
李唯銘
時間:
2024-7-13 16:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int a,pay,money,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<<"正確無誤-1 需要修改-2";
cin>>a;
if(a=1){
cout<<endl<<"總共"<<sum<<"元"<<endl;
cout<<"客人付了多少錢: ";
cin>>pay;
if(pay<0)
goto re;
money=pay-sum;
if(money==0)
{
cout<<endl<<"剛剛好!銘謝惠顧!"<<endl;
}else if(money<0)
{
cout<<endl<<"錢不夠喔!還差"<<-money<<"元!"<<endl;
}else if(money>=1000)
{
cout<<endl<<"錢太多?全部送我吧!"<<endl;
}else
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500; //money=money%500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>0)
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
cout<<endl;
}
else if(a=2){
goto re2;
}
else{
goto re2;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
林少謙
時間:
2024-7-13 22:33
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
string a[]{"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 ",};
int b[]={450,550,325,200,660,150,380};
int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"商品價目表"<<endl;
for(int i=0; i<7; i++)
{
cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
}
cout<<"<8>結帳"<<endl;
cout<<endl;
int x,y,z=-1,w=-1,sum=0;
re2:
cout<<"請輸入商品代碼:";
cin>>x;
if(x==8)
{
goto out;
}
else if(x>=1&&x<=7)
{
cout<<"請輸入購買數量:";
cin>>y;
z++;
sum+=b[x-1]*y;
c[z]+=y;
d[z]+=x;
goto re2;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
out:
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"------------------------"<<endl;
for(int i=0 ; i<=30 ;i++)
{
if(d[i]!=0)
{
cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
}
}
cout<<"-------------------------"<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
int q,r;
re3:
cout<<"1-正確無誤\t2-重新輸入";
cin>>q;
if(q==1)
{
goto out2;
}
else if(q==2)
{
goto re;
}
else
{
cout<<"輸入錯誤 重新輸入";
goto re3;
}
out2:
cout<<endl;
cout<<"請付帳:";
cin>>r;
if(r<sum)
{
cout<<"您付的金額不足,還差"<<sum-r<<"元!"<<endl;
goto out2;
}
else if(r>sum)
{
cout<<endl;
cout<<"找您"<<r-sum<<"元"<<endl;
int e=r-sum;
if(e>=1000)
cout<<"1000元鈔票"<<e/1000<<"張"<<endl;
e%=1000;
if(e>=500)
cout<<"500元鈔票"<<e/500<<"張"<<endl;
e%=500;
if (e>=100)
cout<<"100元鈔票"<<e/100<<"張"<<endl;
e%=100;
if(e>=50)
cout<<"50元硬幣"<<e/50<<"個"<<endl;
e%=50;
if(e>=10)
cout<<"10元硬幣"<<e/10<<"個"<<endl;
e%=10;
if(e>=5)
cout<<"5元硬幣"<<e/5<<"個"<<endl;
e%=5;
if(z>=1)
cout<<"1元硬幣"<<e/1<<"個"<<endl;
}
else if(r==sum)
{
cout<<"剛剛好,謝謝惠顧"<<endl;
}
else
{
cout<<"輸入錯誤 重新輸入"<<endl;
goto out2;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
高湘庭
時間:
2024-7-14 20:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
while(true){
system("cls");
int p,q, sum = 0;
int t[7]={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;
while(true){
cout<<"請輸入商品代碼"<<endl;
cin>>p;
if(p==8)
break;
else if(p>=1&&p<=7){
cout<<"數量:";
cin>>q;
sum+=price[p-1]*q;
t[p-1]+=q;
}
else{
cout<<"無效的商品代碼,請重新輸入"<<endl;
}
}
cout<<"=================="<<endl;
cout<<"[購物清單]"<<endl;
for(int i=0;i<7;i++){
if(t[i]>0)
cout<<name[i]<<"\t\t"<<price[i]<<"*"<<t[i]<<"個"<<endl;
}
cout<<"===================="<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
int option;
cout<<"1-正確無誤 2-重新選購";
cin>>option;
switch(option){
case 1:
cout<<"請付帳:";
int money;
cin>>money;
if(money<sum)
cout<<"付款金額不足,還差"<<sum-money<<"元"<<endl;
else{
cout<<"找您"<<money-sum<<"元";
int c=money-sum;//change
{
if(c>=500)
cout<<"500元鈔票"<<c/500<<"張"<<endl;
c%=500;
if (c<500&&c>=100)
cout<<"100元鈔票"<<c/500<<"張"<<endl;
c%=100;
if(c>=50&&c<100)
cout<<"50元硬幣"<<c/50<<"個"<<endl;
c%=50;
if(c>=10&&c<50)
cout<<"10元硬幣"<<c/10<<"個"<<endl;
c%=10;
if(c>=5&&c<10)
cout<<"5元硬幣"<<c/5<<"個"<<endl;
c%=5;
if(c>=1&&c<5)
cout<<"1元硬幣"<<c/1<<"個"<<endl;
c%=1;
}
}
break;
case 2:
continue;
default:
cout<<"Error,無效的選擇"<<endl;
break;
}
system("pause");
}
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-20 14:50
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
re:
system("cls");
int x,y,sum=0;
int t[7]={0};
string n[7]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int p[7]={450,550,325,200,660,150,380};
cout<<"***智能玩具店***"<<endl;
cout<<"[價目表]"<<endl;
for(int i=0;i<7;i++)
cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl;
re2:
cout<<"請輸入商品代號: "<<endl;
cin>>x;
if(x==8)
goto checkout;
else if(x>=1&&x<=7){
cout<<"輸入數量"<<endl;
cin>>y;
sum+=p[x-1]*y;
t[x-1]=t[x-1]+y;
goto re2;
}
else
goto re;
checkout:
cout<<"[購物清單]"<<endl;
cout<<"--------------------------------"<<endl;
for(int i=0;i<7;i++){
if(t[i]>0)
cout<<n[i]<<"\t"<<p[i]<<"元*"<<t[i]<<endl;
}
cout<<"--------------------------------"<<endl;
cout<<"總共"<<sum<<"元"<<endl;
int option ,money;
cout<<"1-正確無誤 2-重新選購"<<endl;
cin>>option;
switch (option){
case 1:
cout<<"請付帳"<<endl;
cin>>money;
if (money<sum)
cout<<"金額不足,還差"<<sum-money<<"元"<<endl;
else if(money==sum)
cout<<"謝謝惠顧"<<endl;
else{
int c=money-sum;
cout<<"找您"<<c<<"元"<<endl;
if(c>=500){
cout<<c/500<<"張500元鈔票"<<endl;
c=c%500;
}
if(c>=100){
cout<<c/100<<"張100元鈔票"<<endl;
c=c%100;
}
if(c>=50){
cout<<c/50<<"個50元硬幣"<<endl;
c=c%50;
}
if(c>=10){
cout<<c/10<<"個10元硬幣"<<endl;
c=c%10;
}
if(c>=5){
cout<<c/5<<"個5元硬幣"<<endl;
c=c%5;
}
if(c>0)
cout<<c<<"個1元硬幣"<<endl;
}
case 2:
break;
default:
cout<<"輸入錯誤"<<endl;
break;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-20 15:16
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
string a[]{"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 ",};
int b[]={450,550,325,200,660,150,380};
int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
cout<<"智能玩具店"<<endl<<endl;
cout<<"價目表"<<endl;
for(int i=0; i<7; i++)
{
cout<<"("<<i+1<<")"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl;
cout<<endl;
int x,y,z=-1,w=-1,sum=0;
re2:
cout<<"請輸入商品代碼:";
cin>>x;
if(x==8)
{
goto out;
}
else if(x>=1&&x<=7)
{
cout<<"請輸入購買數量:";
cin>>y;
z++;
sum+=b[x-1]*y;
c[z]+=y;
d[z]+=x;
goto re2;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
out:
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"------------------------"<<endl;
for(int i=0 ; i<=30 ;i++)
{
if(d[i]!=0)
{
cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
}
}
cout<<"-------------------------"<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
int q,r;
re3:
cout<<"1-正確無誤\t2-重新輸入";
cin>>q;
if(q==1)
{
goto out2;
}
else if(q==2)
{
goto re;
}
else
{
cout<<"輸入錯誤 重新輸入";
goto re3;
}
out2:
cout<<endl;
cout<<"請付帳:";
cin>>r;
if(r<sum)
{
cout<<"您付的金額不足,還差"<<sum-r<<"元!"<<endl;
goto out2;
}
else if(r>sum)
{
cout<<endl;
cout<<"找您"<<r-sum<<"元"<<endl;
int e=r-sum;
if(e>=1000)
cout<<"1000元鈔票"<<e/1000<<"張"<<endl;
e%=1000;
if(e>=500)
cout<<"500元鈔票"<<e/500<<"張"<<endl;
e%=500;
if (e>=100)
cout<<"100元鈔票"<<e/100<<"張"<<endl;
e%=100;
if(e>=50)
cout<<"50元硬幣"<<e/50<<"個"<<endl;
e%=50;
if(e>=10)
cout<<"10元硬幣"<<e/10<<"個"<<endl;
e%=10;
if(e>=5)
cout<<"5元硬幣"<<e/5<<"個"<<endl;
e%=5;
if(z>=1)
cout<<"1元硬幣"<<e/1<<"個"<<endl;
}
else if(r==sum)
{
cout<<"剛剛好,謝謝惠顧"<<endl;
}
else
{
cout<<"輸入錯誤 重新輸入"<<endl;
goto out2;
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-20 15:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int x, y, z, a, money ,sum=0;
int t[7]={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>>x;
if(x==8)
{
cout<<endl;
goto checkout;
}
else if(x>=1 && x<=7)
{
cout<<"數量: ";
cin>>y;
sum+=price[x-1]*y;
t[x-1]=t[x-1]+y;
goto re2;
}
checkout:
cout<<"[購物清單]"<<endl;
cout<<"============================"<<endl;
for(int i=0; i<7; i++)
{
if(t[i]>0)
cout<<name[i]<<"\t"<<price[i]<<"元"<<" x "<<t[i]<<"個"<<endl;
}
cout<<"============================"<<endl;
cout<<"總共"<<sum<<"元!"<<endl<<endl;
cout<<"1-正確無誤 2-重新選購 ";
cin>>z;
cout<<endl;
if(z==2)
{
goto re;
}
else if(z==1)
{
re3:
cout<<"請付帳: ";
cin>>a;
cout<<endl;
if(a<sum)
{
cout<<"您付的錢不夠, 還差"<<sum-a<<"元!"<<endl<<endl;
goto re3;
}
else if(sum<a)
money=a-sum;
cout<<"找您"<<money<<"元!"<<endl;
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"一元硬幣"<<money/1<<"枚"<<endl;
money%=1;
}
}
system("pause");
goto re;
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-25 10:18
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
re:
system("cls");
int x,y,sum=0;
string n[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
int qty[]={0,0,0,0,0,0,0};
cout<<"****智能玩具店****"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
cout<<"("<<i+1<<")"<<n[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
cout<<"[優惠方案] 滿五千享9折優惠"<<endl<<endl;
re2:
cout<<"請輸入商品代碼:";
cin>>x;
if (x==8)
goto checkout;
if(x>=1 && x<=7)
{
cout<<"請輸入商品數量:";
cin>>y;
sum=sum+price[x-1]*y;
qty[x-1]+=y;
goto re2;
}
else
goto re;
checkout:
cout<<endl<<"[購物清單]"<<endl;
cout<<"----------------------------------------------"<<endl;
for(int i=0;i<=7;i++){
if(qty[i]!=0)
cout<<n[i]<<"\t"<<price[i]<<"*"<<qty[i]<<"個"<<endl;
}
cout<<"----------------------------------------------"<<endl;
cout<<"總共"<<sum<<"元!"<<endl;
if(sum>=5000)
cout<<"由於消費滿五千,享九折優惠"<<endl<<"您只需要付"<<sum*0.9<<"元,現省"<<sum*0.1<<"元"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2