this is about making a loop for powers

stripe3 is the variable
how do u do stripe3*10 stripe3 times
for example if stripe3 = 5
then my question is how do u do 5*10 5 times
because there isnt an opperation in c++ for exponents
so i was thinking of making a loop but i can't figure out
how to write a loop for this ?

also sence before hand i am going to have a user input a value for a couple things including stripe3 and then the loop will calculate then out put the answer any ways im wondering if i should use cin and cout or printf and scanf for the user input stuff also i cant seem to figure out how to combine a user input with cin and cout with loops and if else statements and the data after compiled comes out wrong.

could you guys help me out with this i'd apreaciate it thanks.

## All 15 Replies >because there isnt an opperation in c++ for exponents

There isn't? I think there is.

o i just looked at something and what it said under math.h was
exe ()
could this be it and if it is i dont have a clue how to use it no that's not it.

well i have looked in alot of places and i cant find one if u know it could u tell me?

#include <math.h>

pow(base, exponent);

ok i created a program for it but now how do i output the result?

``````#include <iostream>
#include <math.h>

using namespace std;
int main()
{
float a,b,c;
a=0;
b=0;
cout<<"enter first stripe number"<<endl;
cin>>a;
cout<<"enter second stripe number"<<endl;
cin>>b;
pow(a,b);

system ("pause");
}``````

a_variable_float = pow(a,b);

so like this?

``````#include <iostream>
#include <math.h>

using namespace std;
int main()
{
float a,b,c;
a=0;
b=0;
cout<<"enter first stripe number"<<endl;
cin>>a;
cout<<"enter second stripe number"<<endl;
cin>>b;
a_variable_float = pow(a,b);

system ("pause");
}``````

so like this?

What I meant was:

Declare another float or better yet a double variable at the begining of
main. Then assign the result of the pow function to that variable.

Then do what you wish with that result that is in the variable. :)

i sorta get what your saying but im confused could u give me an example?

o waite i think i get it but when i compiled and ran it i first entered 2 then 5 and got 32 and that doesnt make sence it should be 200000.
heres the code and pleas corect me if im wrong

``````#include <iostream>
#include <math.h>

using namespace std;
int main()
{
float a,b,c;
a=0;
b=0;
c=0;
cout<<"enter base"<<endl;
cin>>a;
cout<<"enter power"<<endl;
cin>>b;
pow(a,b);
c = pow(a,b);
cout<<c;

system ("pause");
}``````

What you are doing is:

2^5 = 2 * 2 * 2 * 2 * 2 = 32
That is correct.

``````#include <iostream>
#include <math.h>

using namespace std;
int main()
{
float a,b,c;
a=0;
b=0;
c=0;
cout<<"enter base"<<endl;
cin>>a;
cout<<"enter power"<<endl;
cin>>b;
pow(a,b); /* you don't need this here */
c = pow(a,b);
cout<<c;

system ("pause");
}``````

o ya your right thats weaird my computter calculator is messed up or something o waite lol no i was doing a logarithmic function i think

o ya your right thats weaird my computter calculator is messed up or something o waite lol no i was doing a logarithmic function i think

Yeah, it helps to know what you want to do, first. :)

well actually i thought i was doing one thing and i was actually doing another

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.