標題:
購物系統 (二)
[打印本頁]
作者:
陳品肇
時間:
2019-2-16 10:18
標題:
購物系統 (二)
本帖最後由 陳品肇 於 2019-2-16 14:39 編輯
[attach]5936[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
string a[7]={"遙控器車","飛機模型","足球 ",
"拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[7]={450,550,325,200,660,
150,380 };
int p,q,sum=0; //p商品代碼 q商品數量
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<a[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼: ";
cin>> p;
if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>> q;
if(q>0) //數量>0
{
sum= sum+ price[p-1]*q; //計算總金額
goto re;
}else //數量<0
{
cout<<"您輸入的數量有誤!!"<<endl;
goto re;
}
}else if(p==8)
{
goto checkout;
}else
{
cout<<"您輸入的代碼有錯!!"<<endl;
goto re;
}
checkout:
cout<<"總金額: "<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2019-2-16 14:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int c=0,sum=0,h;
int n[7]={450,550,325,200,660,150,380};
string s[7]={"遙控器車","飛機模型","足球 ","拼圖 ","玩具槍","可愛玩偶","籃球 "};
cout<<"***智能玩具店***"<<endl;
cout<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<"<"<<i+1<<">"<<s[i]<<"\t"<<n[i]<<endl;
}
cout<<"(8)結帳"<<endl;
re:
cout<<"請輸入商品代碼:";
cin>>c;
if (c>=1 && c<=7)
{
cout<<"數量:";
cin>>h;
if(h>0)
{
sum+=n[c-1]*h;
}else
{
cout<<"錯誤"<<endl;
}
goto re;
}else if(c==8)
{
cout<<"總共:"<<sum<<endl;
}else
{
cout<<"輸入失敗"<<endl;
goto re;
}
system("pause");
return 0;
}
複製代碼
作者:
章幼莛
時間:
2019-2-16 14:39
本帖最後由 章幼莛 於 2019-2-16 14:46 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n,x,sum;
cout<<"☆★☆智能玩具店☆★☆"<<endl;
cout<<endl;
cout<<"[商品價目表]"<<endl;
string f[7]={"遙控汽車",
"飛機模型",
"足球 ",
"拼圖 ",
"玩具槍 ",
"可愛玩偶",
"籃球 "};
int g[7]={450,550,325,200,660,150,380};
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<f[i]<<"\t"<<g[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl;
cout<<endl;
re:
cout<<"請輸入商品代碼:";
cin>>n;
if(n>=1 && n<=7)
{
cout<<"數量:";
cin>>x;
if(x>=0)
{
sum=sum+g[n-1]*x;
goto re;
}else
{
cout<<"您輸入的數量有誤"<<endl;
goto re;
}
}else if(n==8)
{
goto checkout;
}else
{
cout<<"您輸入的商品代碼有誤!"<<endl;
goto re;
}
checkout:
cout<<"總金額:"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
回復
1#
陳品肇
作者:
吳孟修
時間:
2019-2-16 14:43
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a[7]={450,550,325,200,660,150,380};
string b[7]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
cout<<"☆★☆智能玩具店☆★☆\n\n[商品價目表]\n";
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<b[i]<<"\t"<<a[i]<<"元"<<"\n";
}
cout<<"(8)結帳\n\n";
int x,y,sum;
re:
cout<<"請輸入商品代碼: ";
cin>>x;
if(x>=1 && x<=7)
{
cout<<"數量: ";
cin>>y;
if(y>0)
{
sum=sum+a[x-1]*y;
goto re;
}
else
{
cout<<"您輸入的數量有誤"<<endl;
goto re;
}
}
else if(x==8)
{
goto checkout;
}
else
{
cout<<"您輸入的代碼有誤"<<endl;
goto re;
}
checkout:
cout<<"\n總共是"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪寬瀧
時間:
2019-2-16 14:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t,j,sum=0;
cout<<"***智能玩具店***"<<endl;
cout<<""<<endl;
cout<<"[商品價目表]"<<endl;
string items[7]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍","可愛玩偶","籃球 "};
int prices[7] = {450,550,325,200,660,150,380};
for(int i=0; i<7; i++)
{
cout<<"("<<i+1<<")"<<items[i]<<"\t";
cout<<prices[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼"<<endl;
cin>>t;
if(t>=1 && t<=7)
{
cout<<"數量:";
cin>>j;
if(j>0)
{
sum= sum+ prices[t-1]*j;
goto re;
}else
{
cout<<"您輸入的數量有誤!!"<<endl;
goto re;
}
}else if(t==8)
{
goto jeb;
}else
{
cout<<"您輸入的代碼有誤"<<endl;
goto re;
}
jeb:
cout<<"總金額: "<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2019-2-16 14:50
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n,c,sum=0;
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
string t[7]={"遙控器車",
"飛機模型",
"足球 ",
"拼圖 ",
"玩具槍 ",
"可愛玩偶",
"籃球 "};
int p[7]={450,550,325,200,660,150,380};
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<t[i]<<"\t"<<p[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
n:
cout<<"請輸入商品代碼:";
cin>>n;
if(n>=1 && n<=7)
{
c:
cout<<"數量:";
cin>>c;
if(c>0)
{
sum=sum+p[n-1]*c;
goto n;
}else
{
cout<<"您輸入的數量錯誤"<<endl;
goto c;
}
}else if(n==8)
{
goto checkout;
}else
{
cout<<"您輸入的商品代碼錯誤"<<endl;
goto n;
}
checkout:
cout<<endl;
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王瑞喻
時間:
2019-2-16 14:50
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n,q,sum=0;//商品代碼,商品數量,總金額
int price[7]={450,550,325,200,660,150,380};
string b[7]={"遙控汽車",
"飛機模型",
"足球 ",
"拼圖 ",
"玩具槍 ",
"可愛玩偶",
"籃球 "};
cout<<"智能玩具店"<<endl<<endl<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<b[i]<<"\t"<<price[i]<<"元";
cout<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼:";
cin>>n;
if(n>=1 && n<=7)
{
cout<<"數量:";
cin>>q;
if(q>0)
{
sum=sum+price[n-1]*q;
goto re;
}else
{
cout<<"您輸入的數量有誤!!"<<endl;
goto re;
}
}else if(n==8)
{
goto checkout;
}else
{
cout<<"您輸入的代碼有誤"<<endl;
goto re;
}
checkout:
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2