I am in a programming class to learn C++. We had to work on a if and else statement problem. Below is my code, and I am trying to figure out why it is halving it.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int age;
double price;
char category;
double finalPrice;
cin >> price;
cin >> age;
cin >> category;
if (age <= 0) {
cout << "Wrong input";
}
if (age > 0 && age <= 5) {
if (category != 'A' || 'a') {
finalPrice = price - (( price * 100)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
else if(category == 'A' || 'a') {
finalPrice = price - (( price * 0)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
}
if (age > 5 && age <= 12) {
if (category != 'B' || 'b') {
finalPrice = price - (( price * 50)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
else if(category == 'B' || 'b') {
finalPrice = price - (( price * 0)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
}
if (age > 12 && age <= 26) {
if (category != 'C' || 'c') {
finalPrice = price - (( price * 60)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
else if(category == 'C' || 'c') {
finalPrice = price - (( price * 0)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
}
if (age > 26 && age <= 60) {
if (category != 'D' || 'd') {
finalPrice = price - (( price * 70)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
else if(category == 'D' || 'd') {
finalPrice = price - (( price * 0)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
}
if (age > 60) {
if (category != 'E' || 'e') {
finalPrice = price - (( price * 80)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
else if(category == 'E' || 'e') {
finalPrice = price - (( price * 0)/100);
cout << fixed;
cout << setprecision(2) << finalPrice;
}
}
return 0;
}
So above is my code for a assignment for school.
When I enter the values 14.56 25 C I get an output of 5.8.2
However my expected output should just be 14.56
Am I just overseeing something? I don't get how it is even getting half.
Thanks!
Aucun commentaire:
Enregistrer un commentaire