Hi guys, here i have a problem, that i have been trying to rectify for past 1 and half hour.
Here in the code, as you can see, When the user Press Y, He get the chance to input the exponent value. There i have added another nested if, so that the cout statement will be output with proper superscripts (2nd, 3rd, 4th etc etc).
But with the nested if in place the "code have no effect error" occur.
#include<iostream.h>
#include<conio.h>
#include<math.h>
int power(int m, int n=2)
{
m=pow(m,n);
return m;
}
int main()
{
clrscr();
char o;
int m,n;
cout<<"Enter the value for base?"<<endl;
cin>>m;
cout<<"Would you like to specify value for exponent?"<<endl;
cout<<"If Yes Press Y else press N"<<endl;
cout<<"NB: If you don't specify a exponent value, the base will be Squared By Default"<<endl;
here:
cin>>o;
if(o=='y'||o=='Y')
{ cout<<"Enter the exponent value"<<endl;
cin>>n;
int c=n%10;
{ if(c==0||c==4||c==5||c==6||c==7||c==8||c==9)
cout<<n<<"th";
else if(c==2)
cout<<n<<"nd";
else(c==3)
cout<<n<<"rd"; }
cout<<" power of base= "<<power(m,n);
}
else if(o=='n'||o=='N')
{ cout<<"Square of base is "<<power(m); }
else
{ cout<<"Wrong Option"<<endl;
cout<<"Enter a valid option (Y/N)"<<endl;
goto here; }
getch();
return 0;
}