how can i make a loop of this

how can i make a loop of this

int volume;
cout<<"Please Enter Volume of Shampoo";
cin>>volume;

if (volume%5 == 0)
{

int su,volume;
double concen;
volume = 100;
su = (volume * concen) / (volume + 5);
cout<<su<<" " <<volume;

}
else
cout<<"error";

how can i make a loop that will result to this

1 Concentration: 90.00% Volume: 50 ml
2 Concentration: 81.00% Volume: 50 ml
3 Concentration: 72.90% Volume: 50 ml
4 Concentration: 65.61% Volume: 50 ml
5 Concentration: 59.05% Volume: 50 ml
6 Concentration: 53.14% Volume: 50 ml
7 Concentration: 47.83% Volume: 50 ml

it will stop when the concentration hits 50 the concentration here is 47.83 because of the formula it doesnt matter but how can i display that it lowers until 50 what looping statement i will use and how to use it?

thank you
How about this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

/* Your existing code ... */

if( volume % 5 == 0 )
    {
    do
        {
         /*    Put your calculation here:    */
        }
            while( su > 50.00 )

    }    /*   if( volume % 5 == 0 )    */

it does not stop looping i also need

to have this kind of out put

1 Concentration: 90.00% Volume: 50 ml
2 Concentration: 81.00% Volume: 50 ml
3 Concentration: 72.90% Volume: 50 ml
4 Concentration: 65.61% Volume: 50 ml
5 Concentration: 59.05% Volume: 50 ml
6 Concentration: 53.14% Volume: 50 ml
7 Concentration: 47.83% Volume: 50 ml
thanks
You have already written the code -- Do you see where I put the comment "Put your calculation here"?
it does not work it just looping into 90 50 90 50 90 50 all over
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>

int main()
{
    int cnt = 0 ;
    std::cout << std::fixed << std::setprecision(2) ;
    for( double concen = 90.0 ; concen > 50.0 ; concen *= 0.9 )
        std::cout << ++cnt << ". concentration " << concen << "%  volume: 50ml\n" ;
}
can i ask what does std do? std::setprecision(2)?
also concen *=0.9 did you alter my formula?

sir what if i can only use void and basic looping ?

thank you for this code its working but i cant understand it

i have only basic skills
> what does std do?

std is a namespace. Names in the standard library are within the namespace std.
http://www.cplusplus.com/doc/tutorial/namespaces/


> std::setprecision(2)?

http://www.cplusplus.com/reference/iomanip/setprecision/


> concen *=0.9

See compund assignment here: http://www.cplusplus.com/doc/tutorial/operators/


> what if i can only use void and basic looping ?

I'm sorry, I don't understand the question. Could you rephrase it?
"> what if i can only use void and basic looping ?" dont mind that sir i can only use this formula

su = (volume * concen) / (volume + 5);

because if the user inputs lesser volume the concentration will be lesser too

please help me its due tommorow im solving the looping problem since yesterday

int su,volume;
double concen;
volume = 100;
su = (volume * concen) / (volume + 5);
cout<<su<<" " <<volume;

how can i loop this its like this

if concentration is not yet 50 repeat formula then displays current concentration then loops until it reaches 50
Last edited on
> i can only use this formula
> su = (volume * concen) / (volume + 5);

So use it; what's the problem?

Something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>

int main()
{
    double volume = 50.0 ;

    int cnt = 0 ;
    std::cout << std::fixed << std::setprecision(2) ;
    for( double concen = 90.0 ; concen > 50.0 ; concen *= 0.9 )
    {
        double su = (volume * concen ) / (volume + 5) ;
        std::cout << ++cnt << ". concentration " << concen << "% su: " << su << '\n' ;
    }
}
i dont know how to

su is the concentration when i remove the concen *0.9 it does not work

actually su and concentration is the same but i dont need the concen *0.9
but when i removed it , the looping is jus 90 81 all over how can i fix it ?
Last edited on
> i dont know how to

I don't think I can be of any more help right now.

You need to read up on (and try out) the basics of writing loops and the like. There are no short cuts.
oh thanks a lot for your help i learn a lot something from you
Topic archived. No new replies allowed.