i have to write a program after the pseudocode that i already have :
Code:
READ X
READ N
Y <-- 1
Counter <-- N
WHILE Counter > 0
Y <-- Y*X
Counter <-- Counter-1
EndWHILE
WRITE Y
That is the algorithm of the program. You must enter a number X that is a float and a N that is int .
my code looks like this but it's not correct when i entered the values it doesn't calculate it right.
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int Y,N,Counter;
float X;
printf("Enter the real number:\n");
scanf("%f",&X);
printf("Enter natural number:\n");
scanf("%d",&N);
Y = 1;
Counter = N;
while(Counter > 0)
{
Y = Y * X;
Counter = Counter-1;
}
printf("The final result is:\n%d",Y);
getch();
}
Do i have to convert Y to float also to work?
when i compile it and test it gives some numbers but not the ones it supose to .
i also must specify this is not portable code its Borland C++ 3.1 DOS version.
Please help me out or tell me where to study more.
Thank You