標題:
[作業]購物系統 (二)
[打印本頁]
作者:
張翼安
時間:
2016-3-18 22:10
標題:
[作業]購物系統 (二)
本帖最後由 張翼安 於 2016-4-23 10:44 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.
作者:
吳承勳
時間:
2016-4-18 17:21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price[7]={790, 870, 110, 230, 950, 770, 375};
string name[8]={"遙控汽車","飛機模型","足球","拼圖","玩具槍","可愛玩偶","籃球","結帳"};
cout << "[商品價目表]" << endl;
for(int i = 0; i < 7; i++)
cout << "(" << i+1 << ")" << name[i] << " " << "\t" << price[i] << "元" << endl;
cout << "(8)" << name[7] <<endl;
int b=0;
int a=0;
while(a!=8){
int c;
cout << "請輸入商品代碼:";
cin >> a;
if(a==8)
break;
cout << "數量:";
cin >> c;
b+=price[a-1]*c;
}
cout << b << endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡季樺
時間:
2016-4-20 14:03
本帖最後由 蔡季樺 於 2016-4-20 14:30 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string name[8]={"火焰藥水","放屁藥水","作夢藥水","打呵欠藥水","超人藥水","打老師藥水","萬能藥水","結帳"};
int money[7]={200,50,100,10,2000,1100,100000000};
int commodity,quantity,checkout=0;
cout<<"~~★☆★沒路用的藥水專賣店☆★☆~~"<<endl;
cout<<"[價目表]"<<endl;
for(int i=0; i<=6; i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"元"<<endl;
}
cout<<"("<<"8"<<")"<<name[7]<<endl;
while(commodity!=8)
{
cout<<"請輸入想要買的商品代碼(結帳按8):";
cin>>commodity;
if(commodity==8)
break;
cout<<"請輸入要買的數量:";
cin>>quantity;
checkout+=quantity*money[commodity-1];
}
cout<<"總共要付"<<checkout<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡庭豪
時間:
2016-4-23 12:04
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int number[7]={450,550,325,200,660,150,380};
string name[8]={"遙控汽車 ","飛機模型 ","足球 ","拼圖 ","玩具gun","可愛玩偶 ","籃球 ","結帳"};
cout<<"======================================"<<endl;
cout<<"===智障玩具店========================="<<endl;
cout<<"......................................"<<endl;
cout<<"===商品價目表========================="<<endl;
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t";
if(i!=7)
{
cout<<number[i]<<"元"<<endl;
}
}
int sum = 0;
while(true)
{
int x=0,y=0;
cout<<"請輸入代碼(按8結帳):";
cin>>x;
if(x==8)
{
break;
}
else
{ cout<<"請輸入數量:";
cin>>y;
}
sum+=number[x-1]*y;
}
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張健勳
時間:
2016-4-23 12:05
#include<iostream>
using namespace std;
int main ()
{
cout<<"☆★☆《影武的網路速食店》☆★☆"<<endl;
cout<<endl;
cout<<"〔商品價目表〕"<<endl;
string list[8]={"薯條","漢堡","可樂","雪碧","奶昔","紅茶","披薩","結帳"};
int money[7]={50,80,45,45,55,45,299};
for ( int i=0 ; i<8 ; i++)
{
cout<<"("<<i+1<<")"<<list[i]<<""<<"\t";
if (i!=7){
cout<<money[i]<<"元"<<endl;
}
}
cout<<endl;
int sum=0;
while (true)
{
int a=0,b=0;
cout<<"請輸入代碼"<<endl;
cin>>a;
if(a==8){
break;
}else{
cout<<"數量"<<endl;
cin>>b;
sum += money[a-1]*b;
}
}
cout<<"收您"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2