无论我输入什么字母,它都会给我第一个选项,我正在寻找错误,但我是新人,到目前为止已经学习了 3 天,所以老实说我没有看到它,我不知道我做错了什么,但是我希望它根据输入的字母提供正确的信息,提前谢谢,代码尚未完成,我正在做在线课程,所以我对此是全新的,(没有代码是课程本身是我逐行制作的)所以这就是为什么它很糟糕,如果你有任何提示,或者只是想开我玩笑,继续吧,我想学习,这会有所帮助,以防有人想知道我正在做的课程是这个(https://www.w3schools.com/CPP/cpp_functions.asp)这就是我到目前为止读过的内容
这是代码,谢谢大家(是的,McAfee 防病毒软件,因为我在一个 cc 工作,他是客户,所以我用它作为练习的例子)
#include <iostream>
#include <string>
using namespace std;
struct Pack {
double Price;
char Package;
};
int main() {
Pack Basic;
Basic.Price = 29.99;
Basic.Package = 'A';
Pack Essential;
Essential.Price = 39.99;
Essential.Package = 'B';
Pack Premium;
Premium.Price = 49.99;
Premium.Package = 'C';
Pack Advance;
Advance.Price = 89.99;
Advance.Package = 'D';
Pack Ultimate;
Ultimate.Price = 199.99;
Ultimate.Package = 'E';
Pack PremiumFam;
PremiumFam.Price = 69.99;
PremiumFam.Package = 'F';
Pack AdvanceFam;
AdvanceFam.Price = 89.99;
AdvanceFam.Package = 'G';
Pack UltimateFam;
UltimateFam.Price = 249.99;
UltimateFam.Package = 'H';
cout << "McAfee Package refund % Multiplier" "\n\n";
cout<< "This program will allow you to get the refund % of any packages" "\n" "Please see Packages below: " "\n\n";
cout<< "A- Basic $29.99" "\n" "B- Essential $39.99 " "\n\n";
cout<< "C- Premium: $49.99" "\n" "D- Advance (Individual) $89.99" "\n" "E- Ultimate (Individual) $199.99" "\n\n";
cout<< "F- Premium (Family) $69.99" "\n" "G- Advance (Family) $69.99" "\n" "H- Ultimate (Family) $249.99" "\n\n";
char Intro;
cout<< "Please select the package by letter assigned: " "\n";
cin>> Intro;
if (Intro = Basic.Package) {
cout<< "The Package selected is: " << "Basic" << "\t" << "At a cost of: $" << Basic.Price;
} else if (Intro = Essential.Package) {
cout<< "The Package selected is: " << "Essential" << "\t" << "At a cost of: $" << Essential.Price;
} else if (Intro = Premium.Package) {
cout<< "The Package selected is: " << "Premium" << "\t" << "At a cost of: $" << Premium.Price;
} else if (Intro = Advance.Package) {
cout<< "The Package selected is: " << "Advance (Individual)" << "\t" << "At a cost of: $" << Advance.Price;
} else if (Intro = Ultimate.Package) {
cout<< "The Package selected is: " << "Ultimate (Individual)" << "\t" << "At a cost of: $" << Ultimate.Price;
} else if (Intro = PremiumFam.Package) {
cout<< "The Package selected is: " << "Premium (Family)" << "\t" << "At a cost of: $" << PremiumFam.Price;
} else if (Intro = AdvanceFam.Package) {
cout<< "The Package selected is: " << "Advance (Family)" << "\t" << "At a cost of: $" << AdvanceFam.Price;
} else {
cout<< "The Package selected is: " << "Ultimate (Family)" << "\t" << "At a cost of: $" << UltimateFam.Price;
}
return 0; }
您错过了等于符号
if (Intro == Basic.Package) {
cout<< "The Package selected is: " << "Basic" << "\t" << "At a cost of: $" << Basic.Price;
} else if (Intro == Essential.Package) {
cout<< "The Package selected is: " << "Essential" << "\t" << "At a cost of: $" << Essential.Price;
} else if (Intro == Premium.Package) {
cout<< "The Package selected is: " << "Premium" << "\t" << "At a cost of: $" << Premium.Price;
} else if (Intro == Advance.Package) {
cout<< "The Package selected is: " << "Advance (Individual)" << "\t" << "At a cost of: $" << Advance.Price;
} else if (Intro == Ultimate.Package) {
cout<< "The Package selected is: " << "Ultimate (Individual)" << "\t" << "At a cost of: $" << Ultimate.Price;
} else if (Intro == PremiumFam.Package) {
cout<< "The Package selected is: " << "Premium (Family)" << "\t" << "At a cost of: $" << PremiumFam.Price;
} else if (Intro == AdvanceFam.Package) {
cout<< "The Package selected is: " << "Advance (Family)" << "\t" << "At a cost of: $" << AdvanceFam.Price;
} else {
cout<< "The Package selected is: " << "Ultimate (Family)" << "\t" << "At a cost of: $" << UltimateFam.Price;
}
Intro == Basic.Package 这是你错过的部分 如果你给它像 Intro = Basic.package 它会将 Intro 分配为 Basic.package 值,它包含这就是你遇到相同错误的问题