219k views
4 votes
Write an application for Cody’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as $25, $22, $15, or $5, accordingly. Display Invalid Entry if the user enters an invalid item.

1 Answer

5 votes

An application for Cody’s Car Care:

#include <iostream>

#include <string>

#include <vector>

using namespace std;

int main()

{

vector<string>stroptions(4);

stroptions[0] = "Oil Change";

stroptions[1] = "Tire Rotation";

stroptions[2] = "Battery Check";

stroptions[3] = "Brake Inspection";

vector<int> intprices(4);

intprices[0] = 45;

intprices[1] = 22;

intprices[2] = 15;

intprices[3] = 10;

int option;

cout<< "Welcome to Joe's Car Care Shop!" <<endl;

cout<< "Choose a service from our menu:" <<endl;

for(int i = 1; i<= 4; i++)

{

cout<< "#" <<i<< ": " <<stroptions[i-1] <<endl;

}

cout<< "Choice: ";

bool loop = true;

while(loop)

{

loop = false;

cin>> option;

switch(option)

{

case 1:

cout<< "\\A " <<stroptions[option-1] << " will be: $" <<intprices[option -1] <<endl;

break;

case 2:

cout<< "\\A " <<stroptions[option -1] << " will be: $" <<intprices[option -1] <<endl;

break;

case 3:

cout<< "\\A " <<stroptions[option -1] << " will be: $" <<intprices[option -1] <<endl;

break;

case 4:

cout<< "\\A " <<stroptions[option -1] <<" will be: $" << intprices[option -1] <<endl;

break;

default:

cout<< "\\You entered an invalid item! Try again!" <<endl;

loop = true;

break;

}

}

}

User Langusten Gustel
by
5.7k points