dimanche 30 mai 2021

C++ Is my code leaning towards becoming spaghetti like? Am I using to many switch statements. Is there something better practice to do? [closed]

I'm attempting to build a "simple" program based on the bus schedule in my area. It displays the 12 available bus stops. Then selecting your departure time and choosing the Ending destination point. What I would like to know before I try to implement the math of the code. Is what' I've written efficient or unnecessary lines of code?

#include <iostream>
using namespace std;

void BusTravelingDistance(){}; //function to do some math from distance in mile/km point a to b
void BusTravelingTime(){}; //function to do some math length of time traveled HH:MM

int main() //Downtown Hilo to Kaumana.
{
    int choice;
    int BusPickUpLocation[12];
    int BusDropOffLocation[11];

    std::cout << "Chose you starting location by Number: " <<endl;
    std::cout << " 1.Prince kuhio plaza, 2.Aupuni center, 3.hilo Airport, 4.Banyan drive,\n 5.Mooheau bus terminal, 6.Waianuenue ave, 7.Arc of hilo, 8.Hilo medical center,\n 9.Ainako ave, 10.Kaumama drive, 11.Genrey subdivision, 12.Kaumama city" <<endl;
    std::cin >> BusPickUpLocation[12];

    switch (BusPickUpLocation[12])
    {
    case 1:

        std::cout << "Pick up at Prince Kuhio Plaze 1. 7:15AM, 2. 10:10AM, 3. 11:30AM, 4. 4:20PM" <<endl;
        std::cout << "What time are is your departure: " <<endl;
        std::cin >> choice;
        switch (choice)
        {
            case 1:
            {
                std::cout << "You bus arrival is at: 7:15AM\n";
                break;
            }
            case 2:
            {
                std::cout << "Your bus arrival is at: 10:10AM\n";
                break;
            }
            case 3:
            {
                std::cout << "Your bus arrival is at: 11:30AM\n";
                break;
            }           
            case 4:
            {
                std::cout << "Your bus arrival is at 4:20pm\n";
                break;
            }
        }    
        break;

    case 2:
        std::cout << "Pick up at Aupuni Center 1. 2:15PM, 2. 4:38PM" <<endl;
        std::cout << "What time are is your departure: " <<endl;
        std::cin >> choice;
        switch (choice)
        {
            case 1:
            { 
                std::cout << "Your bus arrival is at 2:15PM\n";
                break;
            }      
            case 2:
            {
                std::cout << "Your bus arrival is at 4:35PM\n";
                break;
            }
        }
        break;
        
    case 3:
        std::cout << "Pick up at Hilo Airport 7:25\n";
        break;

    case 4:
        std::cout << "Pick up at Banyon Drive 1. 8:30AM, 2. 10:20AM, 3. 11:40AM";
        std::cout << "What time are is your departure: " <<endl;
        std::cin >> choice;
        switch (choice)
        {
        case 1:
            {
                std::cout << "Your bus arrival is at 8:30AM\n";
                break;
            }      
        case 2:
            {
                std::cout << "Your bus arrival is at 10:20AM\n";
                break;
            }               
        case 3:
            {
                std::cout << "Your bus arrival is at 11:40AM\n";
                break;
            }
        }
        break;
    case 5:
        std::cout << "Pick up at Mo Oheau Bus Terminal 1. 7:35AM, 2. 8:35AM,  3. 10:25AM, 4. 11:45AM, 5. 2:20PM, 6. 4:45PM";
        std::cout << "What time are is your departure: " <<endl;
        std::cin >> choice;
        switch (choice)
        {
        case 1:
            {
                std::cout << "Your bus arrival is at 7:35AM\n";
                break;
            }
        case 2:
            {
                std::cout << "Your bus arrival is at 8:35AM\n";
                break;
            }
        case 3:
            {
                std::cout << "Your bus arrival is at 10:25AM\n";
                break;
            }
        case 4:
            {
                std::cout << "Your bus arrival is at 11:45AM\n";
                break;
            }
        case 5:
            {
                std::cout << "Your bus arrival is at 2:20PM\n";
                break;
            }
        case 6:
            {
                std::cout << "Your bus arrival is at 4:45PM\n";
                break;
            }
        }
        break;

    case 6:
        std::cout << "Pick up at Waianuenue Ave(post office,library,hilo high) 1. 8:40AM, 2. 10:30AM, 3. 11:55AM, 4. 2:25PM, 5. 4:50PM";
        std::cout << "What time are is your departure: " <<endl;
        std::cin >> choice;
        switch(choice)
        {
            case 1:
            {
                std::cout << "Your bus arrival is at 8:40AM\n";
                break;
            }
            case 2:
            {
                std::cout << "Your bus arrival is at 10:30AM\n";
                break;
            }
            case 3:
            {
                std::cout << "Your bus arrival is at 11:55AM\n";
                break;
            }
            case 4:
            {
                std::cout << "Your bus arrival is at 2:25PM\n";
                break;
            }
            case 5:
            {
                std::cout << "Your bus arrival is at 4:50PM\n";
                break;
            }
        }
        break;
    
    case 7:
        std::cout << "Pick up at Ark of Hilo 7:44AM, 8:44AM, 10:34AM, 11:59AM, 2:29PM";
        break;

    case 8:
        std::cout << "Pick up at Hilo Medical Center 7:45AM, 8:45AM, 10:353AM, 12:00PM, 2:30PM, 4:55PM";   
        break; 

    case 9:
        std::cout << "Pick up at Ainako Ave 7:50AM, 8:50AM, 10:40AM, 12:05PM, 2:35PM, 5:00PM";   
        break; 

    case 10:
        std::cout << "Pick up at Kaumana Drive 2:40PM";   
        break; 

    case 11:
        std::cout << "Pick up at Gentry Subdivision 5:10PM";  
        break; 
    default:
        std::cout << "Final Stop Kaumama City 9:00AM, 12:15PM, 2:50PM, 5:20PM\n Heading back to Hilo from Kaumana City?\n I haven't gotten that far into the program... ";
    }


    std::cout << "What is the drop off location: " <<endl;
    std::cout << "1.Aupuni center, 2.hilo Airport, 3.Banyan drive,\n 4.Mooheau bus terminal, 5.Waianuenue ave, 6.Arc of hilo, 7.Hilo medical center,\n 8.Ainako ave, 9.Kaumama drive, 10.Genrey subdivision, 11.Kaumama city" <<endl;
    std::cin >> BusDropOffLocation[11];

}

Aucun commentaire:

Enregistrer un commentaire