-2

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; 
}
  • 4
    Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). `cin >> concession, child, adult;` does not do what you think it does. – NathanOliver Mar 13 '17 at 11:50
  • @NathanOliver I am under the impression that it takes the input as either concession, child or adult? Please correct me if I'm wrong. – FutureProgrammer Mar 13 '17 at 11:52
  • No. It is the comma operator. In this case `cin >> concession` is the only thing that does something. `, child, adult;` is basically ignored. See: https://en.wikipedia.org/wiki/Comma_operator – NathanOliver Mar 13 '17 at 11:54
  • @NathanOliver Ahhh. So how would I separate this so that all three inputs are taken? – FutureProgrammer Mar 13 '17 at 11:55
  • see: http://stackoverflow.com/questions/7425318/multiple-inputs-on-one-line – NathanOliver Mar 13 '17 at 11:58
  • 3
    Although in your case it looks like you need to read in the variable and then decide what to do. That is a little more involved and would be covered in the books. – NathanOliver Mar 13 '17 at 11:59
  • @NathanOliver Chaining doesn't work in this case, although thank you for your help :) – FutureProgrammer Mar 13 '17 at 12:02

1 Answers1

0
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.

BusyProgrammer
  • 2,783
  • 5
  • 18
  • 31