標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2016-8-6 09:55
標題:
購物系統 (二)
本帖最後由 tonyh 於 2016-8-6 11:11 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[7]={"遙控器車",
"飛機模型",
"足球 ",
"拼圖 ",
"玩具槍 ",
"可愛玩偶",
"籃球 "};
int price[7]={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;
while(true) //無窮迴圈
{
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
break; //跳出所在迴圈
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
continue; //跳下一輪迴圈
}
sum+=(price[p-1]*q);
}else
{
cout<<"輸入錯誤!"<<endl;
continue; //跳下一輪迴圈
}
}
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃茂勛
時間:
2016-8-6 11:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p, q, sum=0;
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
string commodity[8]={"新生兒",
"大小便",
"阿嬤丸",
"發瘋藥水",
"甲狀腺",
"廁所清潔劑",
"山寨包包LV",
"結帳"};
int price[7]={20,
3000,
500,
20,
600,
10,
8000,};
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
{
cout<<"("<<i+1<<")"<<commodity[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)"<<commodity[7]<<endl<<endl;
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==8)
{
break;
}else if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>>q;
if(q<=0)
{
cout<<"輸入錯誤!"<<endl;
continue;
}
sum+=(price[p-1]*q);
}else
{
cout<<"輸入錯誤!"<<endl;
continue;
}
}cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陸長辰
時間:
2016-8-6 11:06
本帖最後由 陸長辰 於 2016-8-6 11:25 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
cout<<"智能玩具店"<<endl<<endl;
cout<<"商品價目表"<<endl;
string a[5]={"統神","警察","假的","海濤法師","老鼠"};
int price[5]={87,20,40,60,80};
for(int i=0;i<5;i++)
{
cout<<"("<<i+1<<")"<<a[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
while(true)
{
cout<<"請輸入商品代碼:";
cin>>p;
if(p==8)
{
break;
}else if(p>=1 && p<=7)
{
cout<<"數量";
cin>>q;
sum+=(price[p-1]*q);
}else
{
cout<<"輸入錯誤"<<endl;
continue;
}
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
}
複製代碼
作者:
高允懋
時間:
2016-8-6 11:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,sum=0;
cout<<"☆★☆沒良心玩具店☆★☆"<<endl<<endl;
string c[5]={"破爛飛機",
"報廢汽車",
"盜版樂高",
"爆破足球",
"超醜公仔",};
int p[5]={499,588,301,886,546};
cout<<"[商品價目表]"<<endl;
for(int i=0; i<5; i++)
{
cout<<"("<<i+1<<")"<<c[i]<<"\t"<<p[i]<<"元"<<endl;
}
cout<<"(6)結帳"<<endl<<endl;
while(true)
{
cout<<"商品代碼:";
cin>>a;
if(a==6)
{
break;
}else if(a>=1 && a<=5)
{
cout<<"數量:";
cin>>b;
if(b<=0)
{
cout<<"輸入錯誤"<<endl;
continue;
}else
{
sum+=p[a-1]*b;
continue;
}
}else
{
cout<<"輸入錯誤"<<endl;
continue;
}
}
cout<<"總共"<<sum<<"元";
system("pause");
return 0;
}
複製代碼
作者:
康湍榆
時間:
2016-8-6 11:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p,q,sum=0;
string name[7]={"飛盤 ",
"熊寶寶",
"足球 ",
"玩具槍",
"拼圖 ",
"筆記本",
"鉛筆 ",};
int price[7]={300,550,230,120,90,20,5};
cout<<"☆★☆智能玩具店☆★☆"<<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<<"請輸入商品代碼:";
cin>>p;
if(p==8)
{
break;
}
else if(p>=1 && p<=7)
{
cout<<"數量:";
cin>>q;
if(q<=0)
{
cout<<"wrong!"<<endl;
continue;
}
sum+=(price[p-1])*q;
}
else
{
cout<<"wrong!"<<endl;
continue;
}
}
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2