# ^power

This is a discussion on ^power within the C Programming forums, part of the General Programming Boards category; i have created a simple calc but how can i make it calculate 3^5 using switch and case... well anywayz ...

1. ## ^power

i have created a simple calc but how can i make it calculate
3^5 using switch and case... well anywayz just in case here is my code

#include <stdio.h>
#include <math.h>

int main()

{
int x,y;
char var;

printf("Type the operator +,-,/,* and your prob in this format 5+5\n");
scanf("%d%c%d",&x,&var,&y);
switch(var)
{
case '+':
break;
case '/':
break;
case '-':
break;
case '*':
break;
case '^':
break;
default:
printf(" please try that again\n ");
system("./a.out");
}
}

2. Look up the pow() function in the help.

3. the calc is being created in linux.. sorry..

This is probably not an efficient way to do this, but anyway:
Code:
```int Result=1;
for(int i=0; i<y; i++)
{
Result*=x;
}```
Assuming x and y is the same as in your code, and y is never less than 0.

5. ya i need it with case... if i do it like that then i will have to redo my code in somewayz

6. >>>
if i do it like that then i will have to redo my code in somewayz
<<<

Your going to have to redo it anyway as what you've got doesn't work!

If you haven't got a power function, (I can't believe Linux does not have a power function, I don't know what it would be called, but it is there somewhere), then you're going to have to calculate it aren't you.

7. Originally posted by xlordt
ya i need it with case... if i do it like that then i will have to redo my code in somewayz
Not that much:
Code:
```case '^':
for(int i=0; i<y; i++)
{
Result*=x;
}