sexta-feira, 30 de novembro de 2012

Calculando com as quatros operações

você digita o nome da operação e o programa faz o resto
e nem adianta tentar engana - lo digitando palavras erradas
porque apesar da simplicidade ele está ápto a te reprovar se isto
for feito, muito bom para iniciantes aprenderem comparações de palavras
usando a função strcmp, e também organizarem if e else de uma forma bem prática.
Então copie e cole o código abaixo:

#include <conio2.h>
#include <stdio.h>
#include <time.h>

void Funcexit(){
system("cls");
time_t hora_atual;
void Janela6();

Janela6();
gotoxy(32,11);
textcolor(LIGHTBLUE);printf("OPERACAO FINALIZADA");
gotoxy(2,23);
Sleep(1800);
gotoxy(20,13);
textcolor(LIGHTCYAN);printf("MUITO OBRIGADO POR TER USADO ESTE PROGRAMA\n");
time(&hora_atual);
gotoxy(20,15);
textcolor(YELLOW);printf("A data e hora atuais são: %s", ctime(&hora_atual));
gotoxy(3,24);Sleep(2800);
exit(0);
}

void Janela5(){
int i=0;
textcolor(12);
for(i=2;i<25;i++) {
gotoxy(1,i); //linha da direita
printf("\xba");
}
for(i=2;i<25;i++) {
gotoxy(80,i);
printf("\xba");//linha da esquerda
}
int index = 0, contador;
char letras[5] = "\xcd";
gotoxy(1,1);
for (contador=0; contador < 80; contador++)
{
printf("%c",letras[index]);//Linha de cima
}
gotoxy(1,24);
for (contador=0; contador < 80; contador++)
{
printf("%c",letras[index]);//Linha de baixo
}
gotoxy(1,1);
printf("\xc9");
gotoxy(80,1);
printf("\xbb");
gotoxy(80,24);
printf("\xbc");
gotoxy(1,24);
printf("\xc8");
}

void Janela6(){
int row,col,timer,load;
col=0;
for(row=2;row<=24;row++)
for(col=3;col<=78;col++)
{
gotoxy(col,row);textbackground(6);printf(" ");
}
col=0;
for(row=5;row<=21;row++)
for(col=6;col<=75;col++)
{
gotoxy(col,row);textbackground(16);printf(" ");
}
}

int main(void){
system("cls");
void Funcexit();
void Janela5();
system("title CALCULANDO COM AS 4 OPERAÇÕES");
int num, num2, cont;
char palavra[25];
char ch;
Janela6();
textcolor(LIGHTRED);gotoxy(28,8);printf("CALCULANDO COM AS 4 OPERAیES");
textcolor(YELLOW);gotoxy(22,10);printf("Programa desenvolvido por:");
textcolor(LIGHTCYAN);gotoxy(49,10);printf("Samuel Lima");
textcolor(LIGHTGREEN);gotoxy(30,12);printf("roccoataca@hotmail.com");
textcolor(LIGHTBLUE);gotoxy(21,14);printf("DIGITE    PARA SAIR OU   PARA CONTINUAR:  ");
textcolor(LIGHTRED);gotoxy(29,14);printf("S");textcolor(LIGHTRED);gotoxy(44,14);printf("C");
gotoxy(21,16);
ch = getche();
if(ch == 'S'){
Funcexit();
}
else if(ch == 'C'){

for (cont=0;; cont++)
{
system("cls");Janela5();
textbackground(BLACK);textcolor(LIGHTRED);
gotoxy(27,3);printf("CALCULANDO COM AS 4 OPERAیES");
textcolor(YELLOW);gotoxy(29,5);printf("roccoataca@hotmail.com");
textcolor(LIGHTCYAN);gotoxy(32,7);printf("DIGITE NO TECLADO");
textcolor(LIGHTBLUE);gotoxy(20,9);printf("SOMA PARA");
textcolor(LIGHTRED);gotoxy(33,9);printf("SOMAR");
textcolor(LIGHTBLUE);gotoxy(20,11);printf("SUB PARA");
textcolor(LIGHTRED);gotoxy(33,11);printf("SUBTRAIR");
textcolor(LIGHTBLUE);gotoxy(20,13);printf("MULT PARA");
textcolor(LIGHTRED);gotoxy(33,13);printf("MULTIPLICAR");
textcolor(LIGHTBLUE);gotoxy(20,15);printf("DIV PARA");
textcolor(LIGHTRED);gotoxy(33,15);printf("DIVIDIR");
textcolor(LIGHTBLUE);gotoxy(20,17);printf("SAIR PARA");
textcolor(LIGHTRED);gotoxy(33,17);printf("FECHAR O PROGRAMA");gotoxy(20,19);
gets(palavra);
if(strcmp(palavra,"SOMA")==0){
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE UM N£MERO: ");
scanf("%d", &num);fflush(stdin);
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE OUTRO N£MERO: ");
scanf("%d", &num2);fflush(stdin);
textcolor(YELLOW);gotoxy(20,21);printf("A SOMA \x90 %d", num + num2);
Sleep(1800);
}
else if(strcmp(palavra,"SUB")==0){
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE UM N£MERO: ");
scanf("%d", &num);fflush(stdin);
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE OUTRO N£MERO: ");
scanf("%d", &num2);fflush(stdin);
textcolor(YELLOW);gotoxy(20,21);printf("A SUBTRAۂO \x90 %d ", num - num2);
Sleep(1800);
}
else if(strcmp(palavra,"MULT")==0){
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE UM N£MERO: ");
scanf("%d", &num);fflush(stdin);
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE OUTRO N£MERO: ");
scanf("%d", &num2);fflush(stdin);
textcolor(YELLOW);gotoxy(20,21);printf("A MULTIPLICAۂO \x90 %d ", num * num2);
Sleep(1800);
}
else if(strcmp(palavra,"DIV")==0){
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE UM N£MERO: ");
scanf("%d", &num);fflush(stdin);
textcolor(YELLOW);gotoxy(20,19);printf("DIGITE OUTRO N£MERO: ");
scanf("%d", &num2);fflush(stdin);
textcolor(YELLOW);gotoxy(20,21);printf("A DIVISÇO \x90 %d  E O RESTO \x90: %d", num / num2, num % num2);
Sleep(1800);
}
else if(strcmp(palavra,"SAIR")==0){
Funcexit();
}
else
{
textcolor(YELLOW);gotoxy(20,19);printf("\aESTA PALAVRA NÇO ESTµ ASSOCIADA A NENHUMA OPERA€ÇO",palavra);
Sleep(1800);
textcolor(LIGHTBLUE);gotoxy(20,21);printf("OU TALVEZ VOC\xd2 TENHA DIGITADO ERRADO!");
Sleep(2800);
}
} // FECHAMENTO DO FOR.
} // FECHAMENTO DO IF C.
else{
textcolor(LIGHTGREEN);gotoxy(36,19);printf ("\aopcao errada!");
Sleep(1000);main();
}
return 0;
} // FECHAMENTO DA FUNÇÃO MAIN.

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.