標題:
購物系統 (三)
[打印本頁]
作者:
周政輝
時間:
2018-3-17 13:44
標題:
購物系統 (三)
本帖最後由 周政輝 於 2018-3-17 15:37 編輯
新增 "購物清單" 功能, 使結帳時能不只計算出價錢, 還能列出細目.
參考執行畫面如下:
[attach]3625[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int Buy[7];
int BuyCount[7];
string item []=
{
"(1)遙控汽車 ",
"(2)飛機模型 ",
"(3)足球 ",
"(4)拼圖 ",
"(5)玩具槍 ",
"(6)可愛玩偶 ",
"(7)籃球 ",
};
int num []={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<item[i]<<num[i]<<"元"<<"\t"<<endl;
}
int pn = 0;
int count =0;
int total = 0;
int index=0;
int number=0;
while(true)
{
while(true)
{
cout<<"代碼:";
cin>>pn;
if(pn==8)
{
break;
}
Buy[index] = pn;
cout<<"數目:";
cin>>count;
BuyCount[index] = count;
total=total+num[pn-1]*count;
index++;
}
cout << "請問是否要繼續購買? (1)要 (2)不要" << endl;
cin>> number;
if(number == 1)
{
// break => 跳離迴圈
// continue => 當我讀到continue 迴圈繼續執行
continue;
}
else
{
cout <<"[購物清單]" <<endl;
cout <<"----------------------"<< endl;
for(int i=0;i<index ;i++) {
cout << item[Buy[i]-1] << "\t" << num [Buy[i]-1] << "元*" << BuyCount[i] << "個"<< endl;
}
cout <<"----------------------"<< endl;
cout<<total<<"元"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-3-17 14:32
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int buy[7];
int tim[7];
int total=0;
int num,many,time=0;
string name[7]={"(1)搖控汽車 ","(2)飛機模型 ","(3)足球 ","(4)拼圖 ","(5)玩具槍 ","(6)可愛玩偶 ","(7)籃球 "};
int price[7]={450,550,325,200,660,150,380};
cout<<" 智能玩具店"<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<=6;i++)
{
cout<<name[i]<<price[i]<<"元";
cout<<endl;
}
cout<<"輸入(8)結帳"<<endl;
re:
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>num;
if(num==8)
break;
buy[time]=num;
cout<<"數量: ";
cin>>many;
tim[time]=many;
total=total+(price[num-1]*many);
time++;
}
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"--------------------------"<<endl;
for(int i=0;i<time;i++)
{
int j=0,k=0;
j=buy[i];
k=tim[i];
cout<<name[j]<<" "<<price[j]<<"元 * "<<k<<"個"<<endl;
}
cout<<"--------------------------"<<endl;
cout<<"總共"<<total<<"元!"<<endl;
system("PAUSE");
return 0;
}
複製代碼
作者:
黃安立
時間:
2018-3-17 14:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int BUY[7];
string name[7]=
{
"(1)搖控汽車 ",
"(2)玩具車 ",
"(3)遙控直升機",
"(4)足球 ",
"(5)籃球 ",
"(6)棒球 ",
"(7)玩具熊 "
};
int num[7]=
{
500 ,
1000,
540 ,
450 ,
660 ,
5 ,
10
};
int index = 0;
cout<<"玩具店"<<endl;
cout<<"價目表"<<endl;
for(int i=0;i<7;i++)
{
cout<<name[i]<<num[i]<<endl;
}
cout<<endl;
int productnumber=0;
int count=0;
int total=0;
cout<<"輸入-1離開"<<endl;
while (true)
{
cout<<"請輸入商品代碼"<<endl;
cin>>productnumber;
if(productnumber==-1)
{
break;
}
BUY[index] = productnumber;
cout<<"請輸入數量"<<endl;
cin>>count;
index++;
}
total=total+(num[count-1]*count);
cout<<"[購物清單]"<<endl;
cout<<"----------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<name[BUY[i]-1]<<endl;
}
cout<<"----------------------"<<endl;
cout<<"總金額為"<<total;
system("pause");
return 0;
}
複製代碼
作者:
黃安立
時間:
2018-3-17 14:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int BUY[7];
int Buycout[7];
string name[7]=
{
"(1)搖控汽車 ",
"(2)玩具車 ",
"(3)遙控直升機",
"(4)足球 ",
"(5)籃球 ",
"(6)棒球 ",
"(7)玩具熊 "
};
int num[7]=
{
500 ,
1000,
540 ,
450 ,
660 ,
5 ,
10
};
int index = 0;
cout<<"玩具店"<<endl;
cout<<"價目表"<<endl;
for(int i=0;i<7;i++)
{
cout<<name[i]<<num[i]<<endl;
}
cout<<endl;
int productnumber=0;
int count=0;
int total=0;
cout<<"輸入-1離開"<<endl;
while (true)
{
cout<<"請輸入商品代碼"<<endl;
cin>>productnumber;
if(productnumber==-1)
{
break;
}
BUY[index] = productnumber;
cout<<"請輸入數量"<<endl;
cin>>count;
Buycout[index] = count;
index++;
}
total=total+(num[count-1]*count);
cout<<"[購物清單]"<<endl;
cout<<"----------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<name[BUY[i]-1]<<"\t"<<num[BUY[i]-1]<<"元 *"<<Buycout[i]<<endl;
}
cout<<"----------------------"<<endl;
cout<<"總金額為"<<total;
system("pause");
return 0;
}
複製代碼
作者:
林峻安
時間:
2018-3-17 15:11
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int buy[7];
int buya[7];
cout<<"智能玩具店"<<endl;
string num[7]={"(1)遙控車","(2)遙控飛機","(3)足球 ","(4)拼圖 ","(5)籃球 ","(6)玩具槍","(7)娃娃"};
int n[7]={750,550,555,78,885,1999,85};
for(int i=0;i<7;i++)
{
cout<<num[i]<<"\t";
cout<<n[i]<<"\t";
cout<<endl;
}
int a=0;
int z=0;
int w=0;
int index=0;
cout<<"輸入-1離開:"<<endl;
while(true)
{
cout<<"商品代碼:"<<endl;
cin>>a;
if(a==-1)
{
break;
}
buy[index]=a;
cout<<"數量:"<<endl;
cin>>z;
buya[index]=z;
w= w+n[a-1]*z;
index++;
}
cout<<"購物清單"<<endl;
cout<<"--------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<num[buy[i]-1]<<"\t"<<n[buy[i]-1]<<"元*"<<buya[i]<<"個" <<endl;
}
cout<<"--------------------"<<endl;
cout<<"總金額:"<<w<<endl;
system("pause");
return 0;
}
複製代碼
作者:
顏詢
時間:
2018-3-17 15:25
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int total=0;
int num,many;
string name[7]={"搖控汽車 ","飛機模型 ","足球 ","拼圖 ","玩具槍 ","可愛玩偶 ","籃球 "};
int price[7]={450,550,325,200,660,150,380};
int Buy[7];
int buycount[7];
int index=0;
cout<<" 智能玩具店"<<endl;
cout<<"商品\t\t金額"<<endl;
for(int i=0;i<=6;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<price[i]<<"元";
cout<<endl;
}
cout<<"輸入(8)結帳"<<endl;
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>num;
if(num==8)
break;
Buy[index] = num;
cout<<"數量: ";
cin>>many;
buycount[index]=many;
total=total+(price[num-1]*many);
index++;
}
cout<<"---------------------"<<endl;
for (int i=0;i<index;i++)
{
cout<<name [Buy[i]-1]<<"\t"<<price[Buy[i]-1]<<"元 * "<<buycount[i]<<endl;
}
cout<<"---------------------"<<endl;
cout<<endl;
cout<<"總共"<<total<<"元!";
system("PAUSE");
return 0;
}
複製代碼
作者:
吳秉翰
時間:
2018-3-17 15:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int buy [7];
int buycount [7];
string item []=
{
"(1)遙控汽車 ",
"(2)飛機模型 ",
"(3)足球 ",
"(4)拼圖 ",
"(5)玩具槍 ",
"(6)可愛玩偶 ",
"(7)籃球 ",
};
int num []={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<item[i]<<num[i]<<"元"<<"\t"<<endl;
}
int pn = 0;
int count =0;
int total = 0;
int index = 0;
int number = 0;
while(true)
{
cout<<"代碼:";
cin>>pn;
if(pn==8)
{
cout<<"確定離開? (1)是 (2)否"<<endl;
cin>>number;
if(number==1)
{
break;
}
else
{
continue;
}
}
buy [index] = pn;
cout<<"數目:";
cin>>count;
buycount [index] = count;
total=total+num[pn-1]*count;
index++;
}
for(int i=0;i<index;i++)
{
cout<<item [buy[i]-1]<<num [buy[i]-1]<<"元*"<<buycount[i]<<"個"<<endl;
}
cout<<total<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林峻安
時間:
2018-3-17 15:35
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int buy[7];
int buya[7];
cout<<"智能玩具店"<<endl;
string num[7]={"(1)遙控車","(2)遙控飛機","(3)足球 ","(4)拼圖 ","(5)籃球 ","(6)玩具槍","(7)娃娃"};
int n[7]={750,550,555,78,885,1999,85};
for(int i=0;i<7;i++)
{
cout<<num[i]<<"\t";
cout<<n[i]<<"\t";
cout<<endl;
}
int a=0;
int z=0;
int w=0;
int index=0;
int number=0;
cout<<"輸入-1離開:"<<endl;
while(true)
{
while(true)
{
cout<<"商品代碼:"<<endl;
cin>>a;
if(a==-1)
{
break;
}
buy[index]=a;
cout<<"數量:"<<endl;
cin>>z;
buya[index]=z;
w= w+n[a-1]*z;
index++;
}
cout<<"是否購買(1)是(2)不要"<<endl;
cin>> number;
if(number==1)
{continue;
}
}
else
{
cout<<"購物清單"<<endl;
cout<<"--------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<num[buy[i]-1]<<"\t"<<n[buy[i]-1]<<"元*"<<buya[i]<<"個" <<endl;
}
cout<<"--------------------"<<endl;
cout<<"總金額:"<<w<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
王駿愷
時間:
2018-3-17 15:36
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int buy[7];
int buycount[7];
cout<<"智能玩具店"<<endl;
string num[7]={"(1)遙控車","(2)遙控飛機","(3)足球 ","(4)拼圖 ","(5)籃球 ","(6)玩具槍","(7)娃娃"};
int n[7]={750,550,555,78,885,1999,85};
for(int i=0;i<7;i++)
{
cout<<num[i]<<"\t";
cout<<n[i]<<"\t";
cout<<endl;
}
int a=0;
int z=0;
int w=0;
int index=0;
int number=0;
cout<<"輸入-1離開:"<<endl;
while (true)
{
while(true)
{
cout<<"商品代碼:"<<endl;
cin>>a;
if(a==-1)
{
break;
}
cout<<"是否繼續購買(1)yes(2)No"<<endl;
cin>>number;
if(number==1)
{
continue;
}
else
{
buy[index]=a;
cout<<"數量:"<<endl;
cin>>z;
buycount[index]=z;
w= w+n[a-1]*z;
index++;
}
}
cout<<"商品金額"<<endl;
cout<<"------------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<num[buy[i]-1]<<"\t"<<n[buy[i]-1]<<"元"<<buycount[i]<<"個"<<endl;
}
cout<<"------------------------"<<endl;
cout<<"總金額:"<<w<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
戴嘉禾
時間:
2018-3-17 15:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"☆★☆智能玩具店☆★☆"<<endl;
int buy[7];
int buycount[7];
string j[7]=
{
"(1)遙控汽車",
"(2)飛機模型",
"(3)足球 ",
"(4)拼圖 ",
"(5)玩具槍 ",
"(6)可愛玩偶",
"(7)籃球 "
};
int n[7]=
{
450,
550,
325,
200,
660,
150,
380
};
for(int i=0;i<7;i++)
{
cout<<j[i]<<"\t"<<n[i]<<"元"<<endl;
}
int king=0;
int index=0;
int num=0;
int count=0;
int total=0;
cout<<"輸入0結帳"<<endl;
while(true)
{
while(true)
{
cout<<"請輸入商品代碼"<<endl;
cin>>num;
if(num==0)
{
break;
}
buy[index]=num;
cout<<"請輸入數量"<<endl;
cin>>count;
buycount[index]=count;
total=total+n[num-1]*count;
index++;
}
cout<<"是否要繼續購買? (1)要 (2)不要"<<endl;
cin>>king;
if(king==1)
{
continue;
}
else
{
cout<<"[購物清單]"<<endl;
cout<<"--------------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<j[buy[i]-1]<<" "<<n[buy[i]-1]<<"元 => "<<buycount[i]<<"個"<<endl;
}
cout<<"--------------------------"<<endl;
cout<<"總金額:"<<total<<endl;
break;
}
}
system("pause");
return 0;
}
複製代碼
作者:
黃安立
時間:
2018-3-17 15:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int BUY[7];
int Buycout[7];
string name[7]=
{
"(1)搖控汽車 ",
"(2)玩具車 ",
"(3)遙控直升機",
"(4)足球 ",
"(5)籃球 ",
"(6)棒球 ",
"(7)玩具熊 "
};
int num[7]=
{
500 ,
1000,
540 ,
450 ,
660 ,
5 ,
10
};
int index = 0;
cout<<"玩具店"<<endl;
cout<<"價目表"<<endl;
for(int i=0;i<7;i++)
{
cout<<name[i]<<num[i]<<endl;
}
cout<<endl;
int jiaho=0;
int productnumber=0;
int count=0;
int total=0;
int number=0;
cout<<"輸入-1離開"<<endl;
while(true)
{
while(true)
{
cout<<"請輸入商品代碼"<<endl;a
cin>>productnumber;
if(productnumber==-1)
{
break;
}
BUY[index] = productnumber;
cout<<"請輸入數量"<<endl;
cin>>count;
Buycout[index] = count;
index++;
total=total+(num[productnumber-1]*count);
}
cout<<"繼續購買? (1)要 (2)不要"<<endl;
cin>>jiaho;
if(jiaho==1)
{
continue;
}
else
{
cout<<"[購物清單]"<<endl;
cout<<"----------------------"<<endl;
for(int i=0;i<index;i++)
{
cout<<name[BUY[i]-1]<<"\t"<<num[BUY[i]-1]<<"元 *"<<Buycout[i]<<endl;
}
cout<<"----------------------"<<endl;
cout<<"總金額為"<<total;
}
}
system("pause");
return 0;
}
複製代碼
作者:
顏詢
時間:
2018-3-17 15:45
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int total=0;
int num,many;
string name[7]={"搖控汽車 ","飛機模型 ","足球 ","拼圖 ","玩具槍 ","可愛玩偶 ","籃球 "};
int price[7]={450,550,325,200,660,150,380};
int Buy[7];
int buycount[7];
int index=0;
int number=0;
cout<<" 智能玩具店"<<endl;
cout<<"商品\t\t金額"<<endl;
for(int i=0;i<=6;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<price[i]<<"元";
cout<<endl;
}
cout<<"輸入(8)結帳"<<endl;
while(true)
{
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>num;
if(num==8)
break;
Buy[index] = num;
cout<<"數量: ";
cin>>many;
buycount[7];
total=total+(price[num-1]*many);
index++;
}
cout<<"是否要繼續購買? (1)要 (2)不要"<< endl;
cin >> number;
if(number ==1)
{
continue;
}
else
{
cout<<"---------------------"<<endl;
for (int i=0;i<index;i++)
{
cout<<name [Buy[i]-1]<<"\t"<<price[Buy[i]-1]<<"元"<<endl;
}
cout<<"---------------------"<<endl;
cout<<endl;
cout<<"總共"<<total<<"元!";
cout<<endl;
}
}
system("PAUSE");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-3-17 15:45
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int buy[7];
int tim[7];
int total=0;
int num,many,time=0,yes,money,give,give1000,give500,give100,give50,give10,give1,last;
string name[7]={"(1)搖控汽車 ","(2)飛機模型 ","(3)足球 ","(4)拼圖 ","(5)玩具槍 ","(6)可愛玩偶 ","(7)籃球 "};
int price[7]={450,550,325,200,660,150,380};
cout<<" 智能玩具店"<<endl;
cout<<"[商品價目表]"<<endl;
while(true)
{
for(int i=0;i<=6;i++)
{
cout<<name[i]<<price[i]<<"元";
cout<<endl;
}
cout<<"輸入(8)結帳"<<endl;
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>num;
if(num==8)
break;
buy[time]=num;
cout<<"數量: ";
cin>>many;
tim[time]=many;
total=total+(price[num-1]*many);
time++;
}
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"--------------------------------"<<endl;
for(int i=0;i<time;i++)
{
int j=0,k=0;
j=buy[i];
k=tim[i];
cout<<name[j]<<" "<<price[j]<<"元 * "<<k<<"個"<<endl;
}
cout<<"-------------------------------"<<endl;
cout<<"總共"<<total<<"元!"<<endl;
cout<<endl;
cout<<"1-正確無誤 2-重新選購 ";
cin>>yes;
if(yes==1)
break;
}
while(true)
{
cout<<endl;
cout<<"請付帳: ";
cin>>money;
if(money<total)
cout<<"您付的錢不夠,還差"<<total-money<<"元!"<<endl;
else
break;
}
if(money>total)
{
give=money-total;
}
if(give>1000)
{
give1000=give/1000;
last=give%1000;
}
else if(last>500)
{
give500=last/500;
last=last%500;
}
else if(last>100)
{
give500=last/100;
last=last%100;
}
else if(last>50)
{
give500=last/50;
last=last%50;
}
else if(last>10)
{
give500=last/10;
last=last%10;
}
else if(last>1)
{
give500=last/1;
last=last%1;
}
cout<<"找您"<<give<<"元!"<<endl;
if(give1000!=0)
{
cout<<"一千元鈔票"<<give1000<<"張"<<endl;
}
else if(give500!=0)
{
cout<<"五百元鈔票"<<give500<<"張"<<endl;
}
else if(give100!=0)
{
cout<<"一百元鈔票"<<give100<<"張"<<endl;
}
else if(give50!=0)
{
cout<<"五十元硬幣"<<give50<<"枚"<<endl;
}
else if(give10!=0)
{
cout<<"五十元硬幣"<<give10<<"枚"<<endl;
}
else if(give1!=0)
{
cout<<"五十元硬幣"<<give1<<"枚"<<endl;
}
system("PAUSE");
return 0;
}
複製代碼
作者:
湯東緯
時間:
2018-3-24 14:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string item []={
"(1)遙控汽車 ",
"(2)飛機模型 ",
"(3)足球 ",
"(4)拼圖 ",
"(5)玩具槍 ",
"(6)可愛玩偶 ",
"(7)籃球 "};
int num []={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<item[i]<<num[i]<<"元"<<"\t"<<endl;
}
int buy[7];
int Number[7];
int index=0;
int total=0;
int pn=0;
int count=0;
cout<<"輸入-1後離開"<<endl;
while(true)
{
cout<<"請輸入商品代碼"<<endl;
cin>>pn;
if(pn==-1){
break;
}
cout<<"數目:";
cin>>count;
buy[index]=pn;
total=total+num[pn-1]*count;
Number[index]=pn;
index++;
}
cout<<"購物清單"<<endl;
cout<<"-------------"<<endl;
for(int i=0;i<index;i++){
cout<<item[buy[i]-1]<<" "<<Number[i]<<endl;
}
cout<<"-------------"<<endl;
cout<<"總共"<<total<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-3-24 21:09
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int total=0;
int num[100];
int many=0;
int time=0;
int yes=0;
int money=0;
int give=0;
int give1000=0,give500=0,give100=0,give50=0,give10=0,give1=0;
int last=0;
int buy[7];
int tim[7];
string name[7]={"(1)搖控汽車 ",
"(2)飛機模型 ",
"(3)足球 ",
"(4)拼圖 ",
"(5)玩具槍 ",
"(6)可愛玩偶 ",
"(7)籃球 "};
int price[7]={450,
550,
325,
200,
660,
150,
380};
cout<<"☆★☆智能玩具店☆★☆"<<endl;
cout<<"[商品價目表]"<<endl;
while(true)
{
for(int i=0;i<=6;i++)
{
cout<<name[i]<<price[i]<<"元";
cout<<endl;
}
cout<<"輸入(8)結帳"<<endl;
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>num;
if(num==8)
break;
buy[time]=num;
cout<<"數量: ";
cin>>many;
tim[time]=many;
total=total+(price[num-1]*many);
time++;
}
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"--------------------------------"<<endl;
for(int i=0;i<time;i++)
{
int j=0,k=0;
j=buy[i];
k=tim[i];
cout<<name[j-1]<<" "<<price[j-1]<<"元 * "<<k<<"個"<<endl;
}
cout<<"-------------------------------"<<endl;
cout<<"總共"<<total<<"元!"<<endl;
cout<<endl;
while(true)
{
cout<<"1-正確無誤 2-重新選購 ";
cin>>yes;
if(yes==1)
break;
if(yes!=1||2)
cout<<"輸入錯誤請重新輸入"<<endl;
}
break;
}
while(true)
{
cout<<endl;
cout<<"請付帳: ";
cin>>money;
if(money<total)
cout<<"您付的錢不夠,還差"<<total-money<<"元!"<<endl;
else
break;
}
give=money-total;
cout<<"找您"<<give<<"元!"<<endl;
if(give>=1000)
{
give1000=give/1000;
last=give%1000;
if(give1000>0)
{
cout<<"一千元鈔票"<<give1000<<"張"<<endl;
}
}
else
{
last=give;
}
if(last>=500)
{
give500=give/500;
last=give%500;
if(give500>0)
{
cout<<"五百元鈔票"<<give500<<"張"<<endl;
}
}
if(last>=100)
{
give100=last/100;
last=last%100;
if(give100>0)
{
cout<<"一百元鈔票"<<give100<<"張"<<endl;
}
}
if(last>=50)
{
give50=last/50;
last=last%50;
if(give50>0)
{
cout<<"五十元硬幣"<<give50<<"枚"<<endl;
}
}
if(last>=10)
{
give10=last/10;
last=last%10;
if(give10>0)
{
cout<<"十元硬幣"<<give10<<"枚"<<endl;
}
}
if(last>=1)
{
give1=last/1;
last=last%1;
if(give>0)
{
cout<<"一元硬幣"<<give1<<"枚"<<endl;
}
}
system("PAUSE");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-3-26 16:22
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int total=0;
int num=0;
int many=0;
int time=0;
int yes=0;
int money=0;
int give=0;
int give1000=0,give500=0,give100=0,give50=0,give10=0,give1=0;
int last=0;
int buy[7];
int tim[7];
string name[7]={"(1)搖控汽車 ",
"(2)飛機模型 ",
"(3)足球 ",
"(4)拼圖 ",
"(5)玩具槍 ",
"(6)可愛玩偶 ",
"(7)籃球 "};
int price[7]={450,
550,
325,
200,
660,
150,
380};
cout<<"☆★☆智能玩具店☆★☆"<<endl;
cout<<"[商品價目表]"<<endl;
while(true)
{
for(int i=0;i<=6;i++)
{
cout<<name[i]<<price[i]<<"元";
cout<<endl;
}
cout<<"輸入(8)結帳"<<endl;
while(true)
{
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>num;
if(num==8)
break;
if(num>8)
cout<<"輸入錯誤請重新輸入"<<endl;
else
break;
}
if(num==8)
break;
buy[time]=num;
cout<<"數量: ";
cin>>many;
tim[time]=many;
total=total+(price[num-1]*many);
time++;
}
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"--------------------------------"<<endl;
for(int i=0;i<time;i++)
{
int j=0,k=0;
j=buy[i];
k=tim[i];
cout<<name[j-1]<<" "<<price[j-1]<<"元 * "<<k<<"個"<<endl;
}
cout<<"-------------------------------"<<endl;
cout<<"總共"<<total<<"元!"<<endl;
cout<<endl;
if(total>=3000)
{
cout<<"由於消費滿三千送炫光溜溜球乙個"<<endl;
}
if(total>=10000)
{
cout<<"由於消費滿萬送千元折價券"<<endl;
}
if(total>=1000)
{
cout<<"由於滿五千享9折優惠,只要付"<<total*0.9<<"元"<<endl;
}
while(true)
{
cout<<"1-正確無誤 2-重新選購 ";
cin>>yes;
if(yes==1)
break;
if(yes!=1||2)
cout<<"輸入錯誤請重新輸入"<<endl;
}
break;
}
while(true)
{
cout<<endl;
cout<<"請付帳: ";
cin>>money;
if(money<total)
cout<<"您付的錢不夠,還差"<<total-money<<"元!"<<endl;
else
break;
}
give=money-total;
cout<<"找您"<<give<<"元!"<<endl;
if(give>=1000)
{
give1000=give/1000;
last=give%1000;
if(give1000>0)
{
cout<<"一千元鈔票"<<give1000<<"張"<<endl;
}
}
else
{
last=give;
}
if(last>=500)
{
give500=last/500;
last=give%500;
if(give500>0)
{
cout<<"五百元鈔票"<<give500<<"張"<<endl;
}
}
if(last>=100)
{
give100=last/100;
last=last%100;
if(give100>0)
{
cout<<"一百元鈔票"<<give100<<"張"<<endl;
}
}
if(last>=50)
{
give50=last/50;
last=last%50;
if(give50>0)
{
cout<<"五十元硬幣"<<give50<<"枚"<<endl;
}
}
if(last>=10)
{
give10=last/10;
last=last%10;
if(give10>0)
{
cout<<"十元硬幣"<<give10<<"枚"<<endl;
}
}
if(last>=1)
{
give1=last/1;
last=last%1;
if(give>0)
{
cout<<"一元硬幣"<<give1<<"枚"<<endl;
}
}
system("PAUSE");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2