如何让每一行都有自己的价格。 [英] How can I make each row has it's own price.

查看:85
本文介绍了如何让每一行都有自己的价格。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想改变代码来自要求我输入每行的价格不要求我输入价格但是每行都有它自己的价格这是我的代码:



I just want to change the code from asking me to enter the price for each row to not ask me to enter the price but already each row has it's own price and this is my code:

#include <iostream>
using namespace std;

int Menu ();
void Show_Seats ();
const char FULL = 'X';
const char EMPTY = '#';
const int rows = 15;
const int columns = 30;
char map [rows][columns];
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;

    cout << "\t*********************************************************" << endl;
    cout << "\t*                                                       *" << endl;
    cout << "\t*               Welcome to MMU Concert                  *" << endl;
    cout << "\t*                                                       *" << endl;
    cout << "\t*********************************************************" << endl;
    cout << endl << endl;
    for (int count = 0; count < rows; count++)
        {
            cout << "Please enter the price for row " << (count + 1) << ": ";
                cin >> price [count];

        }
    for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
                map [i][j] = EMPTY;
        }
int choice;
    do
    {
        choice = Menu();
        switch (choice)
        {
            case 1:
                cout << "View Seat Prices\n\n";

                for (int count = 0; count < rows; count++)
                {
                    cout << "The price for row " << (count + 1) << ": ";
                    cout << price [count] << endl;
                }
                break;
            case 2:
                cout << "Purchase a Ticket\n\n";
                do
                {
                    cout << "Please select the row you would like to sit in: ";
                    cin >> row2;
                    cout << "Please select the seat you would like to sit in: ";
                    cin >> column2;
                    if (map [row2] [column2] == '*')
                        {
                            cout << "Sorry that seat is sold-out, Please select a new seat.";
                            cout << endl;
                        }
                    else
                    {
                        cost = price [row2] + 0;
                        total = total + cost;
                        cout << "That ticket costs: " << cost << endl;
                        cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
                        cin >> answer;
                        seat = seat - answer;
                        seat2 += answer;

                        if (answer == 1)
                        {
                            cout << "Your ticket purchase has been confirmed." << endl;
                            map [row2][column2] = FULL;
                        }
                        else if (answer == 2)
                        {
                            cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
                            cout << endl;
                            cin >> Quit;
                        }

                        cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
                        cin >> Quit;
                    }
                }
                while (Quit == 1);

                break;
            case 3:
                cout << "View Available Seats\n\n";
                Show_Seats ();
                break;
            case 4:
                cout << "Total ticket sales: "<<total<<".\n\n";
                break;
            case 5:
                cout << "Quit\n";
                break;
            default : cout << "Error input\n";
        }
    } while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//**                                                                            **
//**                              Define Functions.                          **
//**                                                                            **
//********************************************************************************
//********************************************************************************

int Menu()
{
    int MenuChoice;
        cout << endl << endl;
        cout << " \tMAIN MENU\n";
        cout << " 1. View Seat Prices.\n";
        cout << " 2. Purchase a Ticket.\n";
        cout << " 3. View Available Seats.\n";
        cout << " 4. View Ticket Sales.\n";
        cout << " 5. Quit the program.\n";
        cout << "_____________________\n\n";
        cout << "Please enter your choice: ";
        cin >> MenuChoice;
        cout << endl << endl;
    return MenuChoice;
}

void Show_Seats ()
{
    cout << "\tSeats" << endl;
    cout << "   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30\n";
        for (int count = 0; count < 15; count++)
        {
            cout << endl << "Row " << (count + 1);
            for (int count2 = 0; count2 < 30; count2++)
            {
                cout << " " <<  map [count] [count2];
            }
        }
            cout << endl;
}





我的尝试:



我只是想看看程序员如何做到这一点



What I have tried:

I just want to see how you programmers can do it

推荐答案

Waht about 数组初始化 - cppreference.com [ ^ ]?
Waht about Array initialization - cppreference.com[^] ?


这篇关于如何让每一行都有自己的价格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆