Search code examples
c++visual-studioprocedural-programming

Unable to find a solution


EDIT: After making revisions to my code, it works as it should. I'm new to C++ so I'm sure that it wont look right to some of you and that you may find errors or things that aren't 'ethical'. Please do let me know if there is anything I can improve on within this program.

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std; 

int main() {

// CUSTOMER TYPE
string customertype; 
string classtype; 
string difficultytype;

// CLASS TYPE
string ballet; 
string salsa; 
string bollywood; 

// DIFFICULTY TYPE
float beginner = 0; 
float intermediate = 0; 
float advanced = 0; 

// CUSTOMER TYPE INPUT
cout << "Enter Customer Type: ";
cin >> customertype;

if (customertype == "concession") {

} else if (customertype == "child") { 

} else if (customertype == "adult") { 

} else 
cout << "\n\tInvalid Choice" << "\n" << endl; 

// CLASS TYPE INPUT
cout << "Enter Class Type: ";
cin >> classtype;

if (classtype == "ballet") { 

} else if (classtype == "salsa") { 

} else if (classtype == "bollywood") { 

} else
cout << "\n\tInvalid Choice" << "\n" << endl;

// DIFFICULTY TYPE INPUT
cout << "Enter Difficulty Level: "; 
cin >> difficultytype; 

if (difficultytype == "beginner") { 

} else if (difficultytype == "intermediate") { 

} else if (difficultytype == "advanced") { 

} else 
cout << "\n\tInvalid Choice" << "\n" << endl; 

// CALCULATION
float totalprice = 0;

if ((customertype == "concession") && (difficultytype == "beginner" && "intermediate" && "advanced")) { 
cout << "\n\tTotal Price: 2.50" << "\n" << endl; 

} else if ((customertype == "child") && (difficultytype == "beginner")) { 
cout << "\n\tTotal Price: 2.50" << "\n" << endl; 

} else if ((customertype == "child") && (difficultytype == "intermediate")) {   cout << "\n\tTotal Price: 3.50" << "\n" << endl;

} else if ((customertype == "child") && (difficultytype == "advanced")) {
cout << "\n\tTotal Price: 4.00" << "\n" << endl; 

} else if ((customertype == "adult") && (difficultytype == "beginner")) { 
cout << "\n\tTotal Price: 4.00" << "\n" << endl; 

} else if ((customertype == "adult") && (difficultytype == "intermediate")) {   cout << "\n\tTotal Price: 5.00" << "\n" << endl;

} else if ((customertype == "adult") && (difficultytype == "advanced")) {
cout << "\n\tTotal Price: 5.50" << "\n" << endl; 

} else 
cout << "\tInvalid Choice" "\n" << "\n" << endl; 

cout << "\n\tCustomer Type: " << customertype << "\n" << endl;
cout << "\n\tClass Type: " << classtype << "\n" << endl;
cout << "\n\tDifficulty Type: " << difficultytype << "\n" << endl;

system("pause"); 
return 0; 
}

Solution

  • cin >> beginner, intermediate, advanced;
    

    The commas in this cin statement do not do exactly what you want them to do. In this expression, only the input for cin >> beginner is taken, while the other 2 variables are completely ignored.

    one way to accept multiple inputs in a single statement is by chaining them:

    cin >> beginner >> intermediate >> advanced;
    

    Alternatively, you can have the cin statement on multiple lines:

    cin >> beginner;
    cin >> intermediate;
    cin >> advanced;
    

    EDIT: based in your comments, you a looking for something like:

    string choice;
    cout << "Enter your choice here: ";
    cin >> choice // no need to use getline() as you only need one word as input
    
    if (choice == "beginner)
        // do stuff
    else if (choice == "intermediate")
        // do stuff
    else if (choice == "advanced")
        // do stuff
    else
        cout << "Invalid choice";
    

    You need to replicate this over all the other instances where you are asking the user to pick one of 3 options.