View Single Post
  #10  
Old 05-26-2004, 07:52 AM
cofruben
Old-EQEmu Developer
 
Join Date: Oct 2002
Location: Spain
Posts: 323
Default

Code:
#include <stdio.h> 
void Calculator();
int main() 
{
	Calculator();
	return 0;
}
void Calculator(){
	int x=0; //  for the loop
	printf("Starting Calculator...\n");
	float numbertwo; 
    float numberone;
	char action;
	float result=0;

	while(x==0){
		 printf("Enter the first number:   "); 
		 scanf("%f", &numberone);
		 printf("\nEnter +,-,* or / :        "); 
		 scanf("%c", &action); 
		 scanf("%c", &action); 
		 printf("\nEnter the second number:  ");
		 scanf("%f",&numbertwo);

		 switch (action) 
		 { 
				case '+': 
					   result=numberone+numbertwo; 
					break; 
				case '-': 
					   result=numberone-numbertwo; 
					break; 
				case '*': 
					   result=numberone*numbertwo; 
					break; 
				case '/': 
					result=numberone/numbertwo; 
					break; 
				default: 
					printf("invalid operator\n"); // non-valid character.
					x=1;
		}
		printf("                          --------\n");
		printf("                          %f\n\n",result); //  prints the result
	}
}
simple code.
Reply With Quote