954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Exponitial Loop

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.

tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

>because there isnt an opperation in c++ for exponents

There isn't? I think there is.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

no that's not it.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

#include

pow(base, exponent);

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

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");
  }
tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

a_variable_float = pow(a,b);

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

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");
  }
tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
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. :)

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

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

tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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");
  }
tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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");
 }
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

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

tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
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. :)

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

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

tayster
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You