I attended my 1st C++ lecture yesterday and learnt this program, after trying to compile & run it in Dev C++, it just runs n goes away in fraction of a second, I don't even know if it shows correct answer or not!
Edit: Snipped for reducing post length and thread redundancy. ;)
See below posts for the corrected version of your program.
#include<iostream>
#include<math.h>
using namespace std;
int main(void)
{
int Number(0), Power(0);
cout<<"Enter a number: ";
cin>>Number;
cout<<"Enter a power to raise it to: ";
cin>>Power;
cout<<endl<<"Number "<<Number<<" raised to a power of "<<Power<<" is: "<<pow(Number,Power)<<endl;
return 0;
}
#include<iostream>
using namespace std;
void power(double,int);
int main()
{
int n;
double m;
char a;
cout<<"Enter the number"<<endl;
cin>>m;
cout<<"You want to raise this number to power 2. Right?";
cout<<endl<<"if YES, enter Y else enter N"<<endl;
cin>>a;
if(a=='Y'||a=='y')
{
n=1;
}
else
{
cout<<"Enter the power to which you want to raise"<<m<<endl;
cin>>n;
}
power(m,n);
}
void power(double m,int n)
{
double x=1;
if(n==1)
{
x=m*m;
}
else
{
for(i=0;i<n;i++)
{
x*=m;
}
}
if(n==1)
{
cout<<"the given number: "<<m;
cout<<"raised to power 2 gives the value: "<<x<<endl;
}
else
{
cout<<"The given number: "<<m;
cout<<"raised to power: "<<n;
cout<<"gives the value: "<<x<<endl;
}
}
#include<iostream>
using namespace std;
int main()
{[b]int i;[/b]
int n;
double m;
char a;
void power(double,int);
cout<<"Enter the number"<<endl;
cin>>m;
cout<<"You want to raise this number to power 2. Right?";
cout<<endl<<"if YES, enter Y else enter N"<<endl;
cin>>a;
if(a=='Y')
{
n=1;
}
else
{
cout<<"Enter the power to which you want to raise"<<m<<endl;
cin>>n;
}
power(m,n);
}
void power(double m,int n)
{[b]int i;[/b]
double x=1;
if(n==1)
{
x=m*m;
}
else
{
for(i=0;i<n;i++)
{
x*=m;
}
}
if(n==1)
{
cout<<"the given number: "<<m;
cout<<"raised to power 2 gives the value: "<<x<<endl;
}
else
{
cout<<"The given number: "<<m;
cout<<"raised to power: "<<n;
cout<<"gives the value: "<<x<<endl;
}
[b]int temp;
cin>>temp;[/b]
}