c++ - Last line ouputs two combined outputs trouble? If else statements -


i'm having hard time trying find why program outputting twice in last output line.

if try inputs of 5 , 500 works when try use bigger number second input 500000 2 different outputs combined in last output line.

below code. i'm pretty sure last if else statements don't see problem.

any appreciate.

#include <iostream> using namespace std;  int main() {     double estimatedsales;     double copyprice;     double netmade;     double firstop_net;     double secondop_net;     double thirdop_net;     double cashbefore = 5000;     double cashafter = 20000;     const double first_rate = .125;     const double second_rate1 = .10;     const double second_rate2 = .14;     double bestprice;       cout << "enter price copy of novel\n";     cin >> copyprice;     cout << "enter estimated number of copies sold\n";     cin >> estimatedsales;      netmade = copyprice * estimatedsales;      cout << "it estimated novel generate $" << netmade << " of revenue.\n" ;      firstop_net = cashbefore + cashafter;     secondop_net = netmade * first_rate;      if (estimatedsales <= 4000) {         thirdop_net = netmade * second_rate1;     } else {          thirdop_net = netmade * second_rate2;     }      cout << "royalties keep option 1 $" << firstop_net <<"\n";     cout << "royalties keep option 2 $" << secondop_net <<"\n";     cout << "royalties keep option 3 $" << thirdop_net <<"\n";      if (firstop_net > secondop_net) {         bestprice = firstop_net;     } else {         cout<< "your best bet go 2nd option $"<< secondop_net;     }     if (bestprice > thirdop_net) {         cout << "your best bet go 1st option $"<< firstop_net;     } else {         cout<< "your best bet go 3rd option $"<<thirdop_net;     }      return 0; } 

this i'm getting:

enter price copy of novel 5 enter estimated number of copies sold 500000 estimated novel generate $2.5e+06 of revenue. royalties keep option 1 $25000 royalties keep option 2 $312500 royalties keep option 3 $350000 best bet go 2nd option $312500your best bet go 3rd option $350000 

this expecting:

enter price copy of novel 5 enter estimated number of copies sold 500000 estimated novel generate $2.5e+06 of revenue. royalties keep option 1 $25000 royalties keep option 2 $312500 royalties keep option 3 $350000 best bet go 3rd option $350000 

the problem code logic in last part, while calculating royalties. simple logic , can reduce amount of code.

here solution:

#include <iostream> using namespace std;  int main() {  double estimatedsales; double copyprice; double netmade; double firstop_net; double secondop_net; double thirdop_net; double cashbefore = 5000; double cashafter = 20000; const double first_rate = .125; const double second_rate1 = .10; const double second_rate2 = .14; double bestprice;   cout << "enter price copy of novel\n"; cin >> copyprice; cout << "enter estimated number of copies sold\n"; cin >> estimatedsales;  netmade = copyprice*estimatedsales;  cout << "it estimated novel generate $" << netmade << " of revenue.\n" ;  firstop_net = cashbefore+cashafter; secondop_net = netmade*first_rate;  if (estimatedsales <= 4000)     { thirdop_net = netmade*second_rate1;     } else { thirdop_net = netmade*second_rate2;     }  cout << "royalties keep option 1 $" << firstop_net <<"\n"; cout << "royalties keep option 2 $" << secondop_net <<"\n"; cout << "royalties keep option 3 $" << thirdop_net <<"\n";  double big = firstop_net;  if(big<secondop_net) {     big = secondop_net; } if(big<thirdop_net) {     big = thirdop_net; }       cout << "your best bet go 1st option $"<< big;     return 0; } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -