bruce845 Posted October 16, 2011 Report Share Posted October 16, 2011 (edited) #include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> // Inclua a conio.h, não esqueça! #include <math.h> void validaSimbolo(char *); void validaValor(char *,double *); double calculaOperacao(char *,double *); int main(int argc,char *argv[]) { double valor[2]; char simbolo; system("TITLE Calculadora"); puts("Digite os numeros de acordo com o padrão: x+y e de ENTER!"); scanf("%lf %c %lf",&valor[0],&simbolo,&valor[1]); validaSimbolo(&simbolo); validaValor(&simbolo,valor); system("CLS"); printf("%lf %c %lf = %lf\n",valor[0],simbolo,valor[1],calculaOperacao(&simbolo,valor)); getch(); return EXIT_SUCCESS; } void validaSimbolo(char *simbolo) { while(!strchr("+-*X/:^",toupper(*simbolo))) { puts("Escreva um operador valido!\a"); *simbolo=toupper(getch()); } return; } void validaValor(char *simbolo,double *valor) { while(strchr("/:",*simbolo)&&valor[1]==0) { puts("Informe um numero diferente de 0 para a divisao!\a"); scanf("%lf",&valor[1]); } return; } double calculaOperacao(char *simbolo,double *valor) { switch(*simbolo) { case '+':return valor[0]+valor[1]; case '-':return valor[0]-valor[1]; case 'X':; case '*':return (valor[0])*(valor[1]); case '/':; case ':':return valor[0]/valor[1]; default:return pow(valor[0],valor[1]); } } Edited October 16, 2011 by bruce845 Quote Link to comment Share on other sites More sharing options...
Question
bruce845
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.