返回列表 發帖

[隨堂測驗] 購物系統 (三)

本帖最後由 李泳霖 於 2024-12-6 19:44 編輯

新增 "購物清單" 功能,使結帳時能不只計算出價錢,還能列出細目。
參考執行畫面如下:

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     string n[7]={"遙控器車","飛機模型","足球  ","拼圖  ","玩具槍","可愛玩偶","籃球  "};
  6.     int p[7]={450,550,325,200,660,150,380};
  7.     int t=0,a,b;
  8.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  9.     cout<<"[商品價目表]"<<endl;
  10.     for(int i=0;i<7;i++)
  11.     {
  12.         cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
  13.     }
  14.     cout<<"(8)結帳"<<endl;
  15.     re:
  16.     cout<<"請輸入商品代碼:";
  17.     cin>>a;
  18.     if(a==8)
  19.         goto checkout;
  20.     cout<<"數量:";
  21.     cin>>b;
  22.     t+=p[a-1]*b;
  23.     goto re;
  24.     checkout:
  25.         cout<<"總共:"<<t<<"元"<<endl;
  26.     system("pause");
  27.     return 0;
  28. }
複製代碼
istak.teach2@gmail.com

此帖僅作者可見
istak.teach2@gmail.com

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表