I can not figure this mistake out

So Whenever I run this program I get choice number 3 even when I know that it shouldn't be.with the inputs that i choose. So I have no clue how to fix it.Could you guys please help me out?
Also how do I have the code how its supoose to be like. (I already tried puting the code in the ('code') part

javascript:tx('code')
//Skycommand
//9-30-15
//Page 259 Question 16
// Author's Pay


// Classes
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
cout << fixed << setprecision(2); //Gives the users two decimal places.
// Variable List
double price;
int copies_estimate;
double fixed_royalties;
double choice1;
double choice2;
double royalties_rates1 = 12.5;
double choice3 ;
double royalties_rates2 = 10;
double royalties_rates3 = 14;

// Recieves the price of the book.
cout << "Please enter the price of the book :";
cin >> price;
if (price <= 0) { //Fail Safe
cout << "You have enter a invalid number, please retry and type in a positive number!" << endl;
system("pause");
return 0;
}
// Recieves the estimate of the number of copies that will be sold
cout << "Good, now please enter the estimate of copies that will be sold :";
cin >> copies_estimate;
if (copies_estimate <= 0) { //Fail Safe
cout << "You have enter a invalid number, please retry and type in a positive number!" << endl;
system("pause");
return 0;
}
cout << "Thank you, now below you will see the best option with the most money being" << endl << "stuffed in your pocket!" << endl << endl;

//Choices

//Choice 1
// Author recieves $5000 when final manuscript of the book is turned in and $20000 when the book is published.
choice1 = 25000;

//Choice 2
// Author recieves 12.5% of all sales.
choice2 = (price * copies_estimate) * (royalties_rates1 / 100) ;

//Choice 3
// For the first 4000 copies sold the author gets 10% for the rest of the copies he gets 14%
choice3 = 0; //This is done because if the number of copies is less than or equal 4000 choice 3,
// the next part of the program will have a number for choice 3.
if (copies_estimate > 4000) {
choice3 = ((copies_estimate - 4000) * royalties_rates3) + (4000 * royalties_rates2);
}

//Now it is time to find out which choice makes the most money.

//Choice 1 wins
if (choice1 > choice2 && choice1 > choice3) {
cout << "Congrats, we have determine that choice three is the best choice for you." << endl;
cout << "You will recieve $" << choice1 << " which gives you the most money." << endl;
cout << "Thank you for using this service." << endl;

}

//Choice 2 wins
if (choice1 < choice2 && choice2 > choice3) {
cout << "Congrats, we have determine that choice three is the best choice for you." << endl;
cout << "You will recieve $" << choice2 << " which gives you the most money." << endl;
cout << "Thank you for using this service." << endl;

}

//Choice 3 wins
if (choice3 > choice2 && choice1 < choice3) {
cout << "Congrats, we have determine that choice three is the best choice for you." << endl;
cout << "You will recieve $" << choice3 << " which gives you the most money." << endl;
cout << "Thank you for using this service." << endl;

}

//Choice 1 and 2 tie
if (choice1 == choice2 && choice1 > choice3 && choice2 > choice3) {
cout << "Congrats, we have determine that two choices which are the best for you." << endl;
cout << "Well you have a choice to either pick choice one or two which both equal $" << choice1 << "." << endl;
cout << "Thank you for using this service." << endl;
}


//Choice 2 and 3 ties
if (choice2 == choice3 && choice2 > choice1 && choice3 > choice1) {
cout << "Congrats, we have determine that two choices which are the best for you." << endl;
cout << "Well you have a choice to either pick choice two or three which both equal $" << choice2 << "." << endl;
cout << "Thank you for using this service." << endl;
}

//Choice 3 and 1 ties
if (choice3 == choice1 && choice3 > choice2 && choice1 > choice2) {
cout << "Congrats, we have determine that two choices which are the best for you." << endl;
cout << "Well you have a choice to either pick choice one or three which both equal $" << choice3 << "." << endl;
cout << "Thank you for using this service." << endl;
}

//End of Program
system("pause");
return 0;
}
javascript:editbox2.editTag('code')
Last edited on
closed account (Eybjz8AR)
i didnt read through all the code but could it be a problem with your syntax. you have if
(choice3 == choice1 && choice3 > choice2) lets say... i shortened it wouldnt you want

if ((choice3 == choice1) && (choice3 > choice2)) the way you write it might confuse the compilers. This probably won't help but the compiler could be compiling in a way you are not expecting it to do.
Part of your code:
1
2
3
4
5
6
//Choice 2 wins
    if (choice1 < choice2 && choice2 > choice3) {
        cout << "Congrats, we have determine that choice three is the best choice for you." << endl;
        cout << "You will recieve $" << choice2 << " which gives you the most money." << endl;
        cout << "Thank you for using this service." << endl;
    }
See your mistake?
Last edited on
Ah I see thanks MiiNiPaa, I thought it might be a simple mistake.
Topic archived. No new replies allowed.