im a beginner in C++ and just finished loops. have this assignment where im just stumped.

question is...you're selling a product where b= net profit per unit sold, l= net loss per unit left unsold ( b and l is entered by the user). basically you have to find the number of units to stock to maximize profit by writing a program which is given by this equation

b/ (b+l) > the summation of p(1-p)^i which is p(1-p)^0 + p(1-p)^1 + ....p(1-p) ^i

p= probability of all units sold which is entered by the user.

The program should give you number of units to maximize profit which is i+1

an example is if b=1, l=2 and p=.01 then i=39 and i+1=40 is the optimal number to stock

so far i have this (the basic) and just don't know how to write the loop for this

#include <cstdlib>

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

int s;

double b, l, p, n;

cout << "Enter the net profit for each unit sold when the season ends: ";

cin >> b;

cout << "\nEnter the net loss for each unit left unsold when the season ends: ";

cin >> l;

cout << "\nEnter the probability of all the units being sold: ";

cin >> p;

s = 0;

n = b / ( b + l );

system("PAUSE");

return EXIT_SUCCESS;

}

again...Iam familiar with loops and made a few programs containing them but this one is a little more complicated for me

thanks

question is...you're selling a product where b= net profit per unit sold, l= net loss per unit left unsold ( b and l is entered by the user). basically you have to find the number of units to stock to maximize profit by writing a program which is given by this equation

b/ (b+l) > the summation of p(1-p)^i which is p(1-p)^0 + p(1-p)^1 + ....p(1-p) ^i

p= probability of all units sold which is entered by the user.

The program should give you number of units to maximize profit which is i+1

an example is if b=1, l=2 and p=.01 then i=39 and i+1=40 is the optimal number to stock

so far i have this (the basic) and just don't know how to write the loop for this

#include <cstdlib>

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

int s;

double b, l, p, n;

cout << "Enter the net profit for each unit sold when the season ends: ";

cin >> b;

cout << "\nEnter the net loss for each unit left unsold when the season ends: ";

cin >> l;

cout << "\nEnter the probability of all the units being sold: ";

cin >> p;

s = 0;

n = b / ( b + l );

system("PAUSE");

return EXIT_SUCCESS;

}

again...Iam familiar with loops and made a few programs containing them but this one is a little more complicated for me

thanks

Topic archived. No new replies allowed.