So I'm new to C++ and I am doing a project that requires the creation of a menu for a simple game.
The project instructions are:
Write a program that will ask the user to purchase a vehicle for their character in a racing game. Tell them how much their character has to spend. Give them a menu of options for buying: 1-Mustang ($55,000), 2-Harley Davidson Motorcyle ($49,000), 3-Jeep ($35,000), 4-Sasuki GSX ($31,000). Use the switch statement and determine how much money the user has left. If the user types in a number other than 1-4, print the message: "Sorry can't process that choice!". The character starts with $60,000. Print the amount of money the character has left.

The code that I have started writing is below:

//This program will allow a user to purchase a car in a racing game

#include <iostream>
#include <iomanip>


using namespace std;

int main()
{
    int choice ; //to hold menu choice
    int charBudget=60000;


//price for vehicle 
    const double 
        Mustang = 55,000
        Harley Davidson=49,000
        Jeep =35,000
        Sasuki= 31,000

//constants for menu choices 
        Mustang = 1,
        Harley Davidson=2,
        Jeep=3,
        Sasuki=4; 


    //Tell user characters budget

    cout<<"You have $60,000 to spend"<< endl;

    //Give the user some instructions

    cout <<"Enter 1-4 to make your choice" << endl;


    //Display the menu to the user 

    cout<< "\t\t Vehicle options for character \n\n"
        <<  "1. Mustang 55,000\n"
        <<  "2. Harley Davidson Motorcycle 49,000\n"
        <<  "3. Jeep 35,000 \n"
        <<  "4. Sasuki GSX 31,000\n"
        <<  "Enter your choice: ";
    cin>> choice;


    //set numeric output formatting.
    cout<<fixed <<showpoint <<setprecision(10);
    //respond to users menu selection

    switch (choice)

    {
    case 1:

    cout<< 60,000-55,000 << endl;


    case 2:
        cout<<60,000-49,000 <<endl;


    case 3:
        cout<<60,000- 35,000<< endl;


    case 4:
        cout<<60,000-31,000<<endl; 

line 16: I'd use int instead of double because there is no need for decimal places.

lines 17-31: remove the commas, numeric literals must not contain commans.
Also, add a comma after each of those lines, then add a semicolon after the last one.

 const int 
        Mustang = 55000,
        Harley Davidson=49000,
        Jeep =35000,
        Sasuki= 31000;

lines 23-26: variable names can not duplicate those in lines 17-31. Use some other names. But you don't need them at all because they are never used in the program, do just delete those lines.

switch statement: you need a break statement as the last like of each case. Without the break all the other cases will also get executed.

line 61: use "" if you want it as a statement that guides the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.