我正在学习C++
。作为一项家庭作业,我已经开始尝试分支......但我并没有完全掌握它......这是我尝试执行的代码(如果我犯了巨大的错误,请耐心等待。 .)
#include <iostream>
using namespace std;
int main () {
int age;
char * yes;
char * no;
bool Rated = Rated ? yes : no;
int ticketPrice = 5;
int discountPrice = ticketPrice - (ticketPrice * 0.1);
int matineePrice = (ticketPrice * 0.5);
int hour = 8 <= hour <= 24;
cout << "Is the movie R_rated? \n";
cin >> yes or no;
cout << "How old are you?";
cin >> age;
if (age < 0 or age >100) {
cout << "Not a valid age!";
}
else if ((age <= 13) and (Rated = yes)) {
cout << "You must be accompanied by a Janitor";
}
else if (((age > 13) and ((Rated = yes) or (Rated = no)))
or ((age <=13) and (Rated = yes))) {
cout << "What time do you want the ticket for?";
cin >> hour;
if (hour < 8 or hour > 24) {
cout << "Not a valid hour!";
}
else if (hour < 18) {
if (age <= 5) {
cout << "The entrance is free";
}
else if (age >= 55) {
cout << "Matinee Ticket price is "<<
matineePrice;
}
else if (5 < age < 55) {
cout << "Matinee ticket price is " << matineePrice;
}
}
else if (hour >= 18) {
if (age <= 5) {
cout << "The entrance is free";
}
else if (5 < age <= 55) {
cout << "Ticket price is " << ticketPrice;
}
else if (age > 55) {
cout << "You're eligibile for a 10% "
"discount \n";
cout << "Ticket price is " << discountPrice;
}
}
}
}
输出:(我回答no,67和20)我应该得到discountedPrice
而不是ticketPrice
值......
Is the movie R_rated?
no
How old are you?67
What time do you want the ticket for?20
Ticket price is 5
任何建议、链接或教程帮助将不胜感激......