Невозможно найти решение

РЕДАКТИРОВАТЬ: После внесения изменений в мой код, он работает как следует. Я новичок в C ++, поэтому я уверен, что некоторые из вас не будут выглядеть правильно, и что вы можете найти ошибки или вещи, которые не являются «этическими». Пожалуйста, дайте мне знать, если есть что-то, что я могу улучшить в этой программе.

#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;
}

-2

Решение

cin >> beginner, intermediate, advanced;

Запятые в этом cin Заявление не делать именно то, что вы хотите, чтобы они сделали. В этом выражении только вход для cin >> beginner берется, а остальные 2 переменные полностью игнорируются.

Один из способов принять несколько входных данных в одном операторе — объединить их в цепочку:

cin >> beginner >> intermediate >> advanced;

В качестве альтернативы вы можете использовать оператор cin в нескольких строках:

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

РЕДАКТИРОВАТЬ: основываясь на ваших комментариях, вы ищете что-то вроде:

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";

Вы должны повторить это во всех других случаях, когда вы просите пользователя выбрать один из 3 вариантов.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]