In: Computer Science
In C++
A new author is in the process of negotiating a contract for a new romance novel. The publisher is offering three options.
The author has some idea about the number of copies that will be sold and would like to have an estimate of the royalties generated under each option.
Instructions
Write a program that prompts the author to enter:
The program then outputs:
(Use appropriate named constants to store the special values such as royalty rates and fixed royalties.)
Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.
Example input:
120 22.99
Expected Output:
25000.0
344.8
275.8
Option 1 is the best
#include <iostream>
using namespace std;
int main()
{
double copies,price,second,third; //Declaring variables
cout<<"\nEnter no of estimated copies: ";
cin>>copies; //Taking no of copies from user
cout<<"\nEnter net price of each copy of the novel: ";
cin>>price; //Taking price from user
cout<<"\nOption 1: $25000"; //Printing option 1
second = price * 0.125 * copies; //Calculating option 2
cout<<"\nOption 2: $"<<second; //Printing option
2
if(copies<4000)
third = price * 0.10 * copies; //Calculating option 3
else
third = (price * 0.10 * 4000) + (price * 0.14 * (copies-4000));
//Calculating option 3
cout<<"\nOption 3: $"<<third; //Printing option 3
if(25000>second && 25000>third) //Checking which
option is best
cout<<"\nOption 1 is best";
else if(second>third)
cout<<"\nOption 2 is best";
else
cout<<"\nOption 3 is best";
return 0;
}
Output:-