Need help with some numbers.

Hello coders. so I have here a code that works great, but here is a little issue I'm having. When input 123456789 for "Enter price of each copy:" and 50 for "Estimated number of copies sold:". The answer I get is 617283945.00, however; the answer is supposed to be 864189523.00. Here is my code:

<code>

#include <iostream>
#include <iomanip>
#include <cmath>

namespace royaltyRates{}
using namespace std;

int main()
{
double option1;
double option2;
double option3;
double copiesSold;
double priceperCopy;
double tenPercent;
double fourteenPercent;
double finalManu;
double published;

cout << fixed << showpoint << setprecision(2);

cout << "Enter price of each copy: ";
cin >> priceperCopy;
cout << "Estimated number of copies sold: ";
cin >> copiesSold;
cout << endl;

finalManu = 5000;
published = 20000;

if (copiesSold <= 4000)
tenPercent = (priceperCopy * copiesSold) * 0.1;

if (copiesSold > 4000)
fourteenPercent = ((priceperCopy * copiesSold) - 4000) * 0.14;

option1 = finalManu + published;
option2 = (priceperCopy * copiesSold) * 0.125;
option3 = tenPercent + fourteenPercent;

cout << "Royalty option1: $ " << option1 << endl;
cout << endl;

cout << "Royalty option2: $ " << option2 << endl;
cout << endl;

cout << "Royalty option3: $ " << option3 << endl;
cout << endl;

if(option1 > option2 && option1 > option3)
cout << "Option 1 is the best option you can choose for maximum royalties.";

if(option2 > option1 && option2 > option3)
cout << "Option 2 is the best option you can choose for maximum royalties.";

if(option3 > option1 && option3 > option2)
cout << "Option 3 is the best option you can choose for maximum royalties.";

return 0;
}

<code>
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

HTML tags don't work here. The site uses BB code tags.
I manually did the calculations on my pc calculator and also got 617..... So it seems rigght for me. Running the program it printed "Option2 is the best..."

From where did you get the 8641...?
Your model answer is wrong. You will get the intended answer if you reverse the inputs and assume that the unit cost is 50 and you sold 123456789 of them. Otherwise, somebody would have grossly overpriced their book!



I presume that the question is this one:
https://www.chegg.com/homework-help/questions-and-answers/instructions-c-redo-programming-exercise-16-chapter-4-named-constants-defined-namespace-ro-q32800399
In summary:
"The publisher is offering three options. In the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. In the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. In the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000."



Your code is also wrong, since it won't set "tenPercent" if copiesSold is greater than 4000, or "fourteenPercent" if copiesSold is less than 4000. The calculation formula for 14% is also bracketed incorrectly.

If the largest two options are equal then your code won't produce a final answer.



In the following code I reversed the inputs to get the "intended" answer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

int main()
{
   double option1, option2, option3;
   int copiesSold;
   double priceperCopy;
   double finalManu;
   double published;

   cout << fixed << showpoint << setprecision(2);
   cout << "Enter price of each copy: "       ;   cin >> priceperCopy;
   cout << "Estimated number of copies sold: ";   cin >> copiesSold;

   finalManu = 5000;
   published = 20000;

   option1 = finalManu + published;
   option2 = priceperCopy * copiesSold * 0.125;
   option3 = priceperCopy * ( min( copiesSold, 4000 ) * 0.1 + max( copiesSold - 4000, 0 ) * 0.14 );

   cout << "Royalty option1: $ " << option1 << '\n'
        << "Royalty option2: $ " << option2 << '\n'
        << "Royalty option3: $ " << option3 << '\n';

   int opt; 
   if ( option1 > option2 && option1 > option3 ) opt = 1;
   else if ( option2 > option3 )                 opt = 2;
   else                                          opt = 3;
   cout << "Option " << opt << " maximises royalties.";
}

Enter price of each copy: 50
Estimated number of copies sold: 123456789
Royalty option1: $ 25000.00
Royalty option2: $ 771604931.25
Royalty option3: $ 864189523.00
Option 3 maximises royalties.


Last edited on
thank you everyone for your hard work. :D
Topic archived. No new replies allowed.