標題:
購物系統 (二)
[打印本頁]
作者:
鄭繼威
時間:
2023-4-21 21:07
標題:
購物系統 (二)
本帖最後由 鄭繼威 於 2023-5-5 20:30 編輯
新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出
總共多少錢
,執行畫面如下圖所示。
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
//商品名稱
string name[]={"遙控汽車","飛機模型","足球\t","拼圖\t","玩具槍","可愛玩偶","籃球\t"};
//商品價格
int price[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
//把選項|名稱|價格輸出
for(int i=0;i<=6;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<endl;
}
cout<<"(8)結帳"<<endl;
int option,qty,sum=0;
re:
cout<<"你要買什麼?";
cin>>option;
//1~7
if(option>=1 and option<=7)
{
//購物
cout<<"你要買幾個?";
cin>>qty;
sum=sum+(price[option-1]*qty);
goto re;
}
else if(option==8)
{
//結帳
goto checkout;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
checkout:
cout<<"總共="<<sum<<endl;
// cout<<"總共="<<price[option-1]*qty<<"錢"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
廖秝瑜
時間:
2023-4-28 20:56
[code]#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,sum=0;
string name[]={"紅茶 ","奶茶 ","牛奶 ","咖啡 ","果汁 "};
int price[]={50,75,60,75,30,};
cout<<"☆★☆智能飲料店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<4; 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<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
[/code]
作者:
曹祁望
時間:
2023-4-28 20:57
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
string names[3]={"餅乾","糖果","飲料"};
int price[3]={5,10,15};
int n;
int opt;
bool keep=true;
int sum=0;
for(int i=0;i<=2;i++){
cout<<i+1<<names[i]<<"\t"<<price[i]<<"\n";
}
cout<<"<4>結帳\n";
while(keep){
cout<<"輸入要買的商品號碼:";
cin>>opt;
if(opt!=1 and opt!=2 and opt!=3){
cout<<"總共"<<sum<<"元\n";
break;
}
else{
cout<<"請輸入數量:";
cin>>n;
sum+=price[opt-1]*n;
}
}
system("pause");
return 0;
}
複製代碼
作者:
張絜晰
時間:
2023-4-28 20:58
#include<cstdlib>
#include<iostream>
using namespace std;
int main(){
string m[8]={"兔子布偶","文具組合","高級餅乾","鍵盤滑鼠","遊戲點數","藍色外套","神秘獎品","結帳"};
int n[8]={100,200,150,800,487,666,999, };
cout<<"雜七雜八雜貨店價目表"<<endl;
for(int a=0;a<7;a++){
cout<<a+1<<"\t"<<m[a]<<"\t"<<n[a]<<"元"<<endl;
}
cout<<"8\t"<<m[7]<<endl;
int o,q,s=0;
re:
cout<<endl<<"請輸入商品代碼:\t";
cin>>o;
if(o>0 && o<8){
cout<<endl<<"請輸入商品數量:\t";
cin>>q;
s=s+(n[o-1]*q);
goto re;
}
else if(o==8){
goto checkout;}
else{
cout<<"輸入錯誤"<<endl;
goto re;
}
checkout:
cout<<"總共是:"<<s<<endl;
system ("pause");
return 0;
}
複製代碼
作者:
何權晉
時間:
2023-4-28 20:58
#include <iostream>
using namespace std;
int main()
{
int p,qty;
int sum=0;
string name[]={"R/C Car", "Model Plane", "Football", "Tennis Ball","Toy Gun","Basketball"};
int price[]={400,690,678,560,570,300};
cout<<"*****Da Epic Toy Store*****"<<endl<<endl;
cout<<"[Products]"<<endl;
for(int i=0;i<=5;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<"$"<<price[i]<<endl;
}
cout<<"(8)Checkout"<<endl<<endl;
re:
cout<<"Enter the number corresponding to the desired product: ";
cin>>p;
if(p>=1 && p<=7)
{
cout<<"Quantity:";
cin>>qty;
sum=sum+(price[p-1]*qty);
goto re;
}else if(p==8)
{
goto checkout;
}
checkout:
cout<<endl<<"Total:"<<"$"<<sum<<endl;
system("pause");
return 0;
}
複製代碼
作者:
盧玄皓
時間:
2023-4-28 21:01
本帖最後由 盧玄皓 於 2023-4-28 21:10 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string n[]={"手槍 ","彈藥 ","98K ","AWM ","M500 ","沙漠之鷹 "};
int p,q,sum=0;
int price[]={10000,450,98000,100000,43000,52000};
cout<<"fire槍械店"<<endl<<endl;
cout<<"[槍械價目表]"<<endl;
for(int i=0;i<6;i++)
{
cout<<"("<<i+1<<")"<<n[i]<<"\t"<<price[i]<<endl;
}
cout<<"(7)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼: ";
cin>>p;
if(p==7)
{
goto checkout;
}else if(p>=1 && p<=6)
{
cout<<"數量: ";
cin>>q;
sum+=price[p-1]*q;
goto re;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
鄭繼威
時間:
2023-4-28 21:02
5
作者:
黃子豪
時間:
2023-4-28 21:02
#include<iostream>
using namespace std;
int main(){
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
int a,b,sum=0;
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++){
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl;
re:
cout<<"請輸入商品代碼: ";
cin>>a;
if(a>=1 and a<=7){
cout<<"數量: ";
cin>>b;
sum+=price[a-1]*b ;
goto re;
}
else if(a==8){
goto checkout;
}
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡沛倢
時間:
2023-4-28 21:03
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string a[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int c[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int b=0;b<7;b++){
cout<<"("<<b+1<<")"<<a[b]<<"\t"<<c[b]<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
int f,g,h=0;
re:
cout<<"請輸入商品代碼,輸入完畢後,請按Enter鍵";
cin>>f;
if(f>=1 and f<=7){
cout<<"請輸入數量:";
cin>>g;
h=h+c[f-1]*g;
goto re;
}
else if(f==8){
goto re2;
}
else{
cout<<"輸入錯誤"<<endl;
}
re2:
cout<<"一共"<<h<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鄭繼威
時間:
2023-4-28 21:04
回復
4#
張絜晰
作者:
邵凡榛
時間:
2023-4-28 21:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
system("cls");
int option,qty,sum;
string name[]={"遙控汽車","飛機模型","玩具槍","玩偶 ","籃球 "};
int price[]={450,550,325,200,660};
cout<<"智能玩具店"<<endl<<endl;
cout<<"商品價目表"<<endl;
for(int i=0;i<=4;i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<endl;
cout<<"(6)結帳"<<endl<<endl;
re:
cout<<"請輸入商品號碼:";
cin>>option;
if(option==6){
goto checkout;
}
else if(option>=1 and option<=4){
cout<<"商品數量:";
cin>>qty;
sum=sum+price[option-1]*qty;
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張桔熙
時間:
2023-4-28 21:07
#include<iostream>
using namespace std;
int main(){
re:
system("cls");
int p,q,sum=0;
string name[]={"傷藥","解麻藥","好傷藥","寶貝球","高級球"};
int price[]={200,400,500,200,800};
cout<<" 寶可夢商店 "<<endl<<endl;
cout<<"[商品價格表]"<<endl;
for(int i=0; i<5; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(6)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼:";
cin>>p;
if(p==6)
{
goto checkout;
}else if(p>=1 && p<=5)
{
cout<<"數量:";
cin>>q;
sum+=price[p-1]*q;
goto re2;
}else
{
goto re;
}
checkout:
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
呂宗晉
時間:
2023-5-5 16:44
#include<iostream>
using namespace std;
int main(){
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
int a,b,sum=0;
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++){
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl;
re:
cout<<"請輸入商品代碼: ";
cin>>a;
if(a>=1 and a<=7){
cout<<"數量: ";
cin>>b;
sum+=price[a-1]*b ;
goto re;
}
else if(a==8){
goto checkout;
}
checkout:
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
呂得銓
時間:
2023-5-5 20:01
本帖最後由 呂得銓 於 2023-5-17 19:36 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string name[]={"遙控汽車","飛機模型","足球\t","拼圖\t","玩具槍","可愛玩偶","籃球\t"};
int price[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<=6;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<endl;
}
cout<<"(8)結帳"<<endl;
int option,qty,sum=0;
re:
cout<<"你要買什麼?";
cin>>option;
if(option>=1 and option<=7)
{
cout<<"你要買幾個?";
cin>>qty;
sum=sum+(price[option-1]*qty);
goto re;
}
else if(option==8)
{
goto checkout;
}
checkout:
cout<<"總共="<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
邱品惟
時間:
2023-8-7 18:11
#include<iostream>
using namespace std;
int main()
{
string name[]={"遙控汽車","飛機模型","足球\t","拼圖\t","玩具槍","可愛玩偶","籃球\t"};
int price[]={450,550,325,200,660,150,380};
int buy,sum=0,amount;
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<=6;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<endl;
}
cout<<"(8)結帳(給錢)"<<endl<<endl;
re:
cout<<"你要買什麼?(代碼)"<<endl;
cin>>buy;
if(buy>=1 and buy<=7)
{
cout<<"你要買幾個?(數字)"<<endl;
cin>>amount;
sum=sum+price[buy-1]*amount;
goto re;
}
else if(buy==8)
{
cout<<"總共"<<sum<<"元"<<endl;
if(sum==0)
{
cout<<"滾!"<<endl;
}
}
else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2