featurez [Archive] - C Board

PDA

View Full Version : featurez


xlordt
02-26-2002, 07:13 AM
ok so far i have my cal calculate - ,+ ,* ,/ and ^ i want to know am i missing something ..? am i missing any featurez...? and another thing iz what if i wanted to calculate another problem how can i make the program run again...when they click on yes(y)... here is the code..

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

int main()

{
int x, y, i;
char var;
int result = 1;


printf("Type the operator +,-,/,* and your prob in this format 5+5\n");
scanf("%d%c%d",&x,&var,&y);
switch(var)
{
case '+':
printf("Answer = %d\n",x+y);
break;
case '/':
printf("Answer = %d\n", x/y);
break;
case '-':
printf("Answer = %d\n", x-y);
break;
case '*':
printf("Answer = %d\n", x*y);
break;
case '^':
{
for(i=0; i<y; i++)

result *=x;

printf("Answer = %d\n", result);
break;
default:
printf(" please try that again\n ");

}

}
}

Govtcheez
02-26-2002, 09:03 AM
^&^ &^&&^ &^ ^&^&&^& ^&^^^ ^& ^&^& ^^& ^^^ ^&&^ &^ & ^&^^&^?

How about if someone wants to take the nth root of a number?

> calculate another problem how can i make the program run again...

Use a while loop...

#include <ctype.h>

char again = 'y';

while(tolower(again) == 'y')
{
//do cool stuff
//Ask if they wanna go again
}

xlordt
02-26-2002, 04:43 PM
i keep getting an error and i cant seem to track it down ....

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

int main()

{
int x, y, i;
char var;
int result = 1;
char again = 'y';

printf("Type the operator +,-,/,* and your prob in this format 5+5 or
if you are working on power then here is the fromat 5^2\n");
scanf("%d%c%d",&x,&var,&y);
switch(var)
{
case '+':
printf("Answer = %d\a\n",x+y);
break;
case '/':
printf("Answer = %d\a\n", x/y);
break;
case '-':
printf("Answer = %d\a\n", x-y);
break;
case '*':
printf("Answer = %d\a\n", x*y);
break;
case '^':
{
for(i=0; i<y; i++)

result *=x;

printf("Answer = %d\a\n", result);
break;
default:
printf(" please try that again\n ");

{
while(tolower(again) == 'y')
{
printf(" would you like to go away ",'y');
}
}

btw can you please tell me alittle about the code that you posted cause i want to be able to understand what you just gave me... thanx

klausi
02-27-2002, 05:55 AM
and another thing iz what if i wanted to calculate another problem how can i make the program run again...when they click on yes(y)...

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

int main()

{
int x, y, i;
char var;
int result = 1;
char again = 'y';

again: /* jumps to that mark after <goto again;> */

printf("Type the operator +,-,/,* and your prob in this format 5+5 or
if you are working on power then here is the fromat 5^2\n");
scanf("%d%c%d",&x,&var,&y);
switch(var)

When you want to make the program run again just put

goto again;

on it.

klausi