Linux - numeros + - y real de modo grafico

 
Vista:

numeros + - y real de modo grafico

Publicado por ulises (1 intervención) el 05/03/2007 23:07:34
APENAS ESTOY APRENDIENDO A PROGRAMAR EN C, Y NOS DEJO NUESTRO MAESTRO COMO HACER QUE DE MODO GRAFICO OBTENGAMOS LO SIGUIENTE,

Un numero entero positivo
Un numero entero negativo
Un numero de punto flotante

Validar todos los casos, hasta ahora estoy he llegado a esto, pero me aparecen muchos errores, espero y alguien me pueda ayudar.


//PRACTICA1.4AUB.CPP
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <graphics.h>

void iniciagraficos()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
}
int Numeropositivo(int x, int y, int colorT, int colorF){
char tecla, cad[40];
int pos, num;
cad[0]='\x0';
do {
gotoxy(x,y);
printf("%s",cad);
setcolor(colorT);
setcolor(colorF);
tecla=getch();
pos=strlen(cad);
if (isdigit(tecla)) {
cad[pos]=tecla;
cad[pos+1]='\x0';
}
if (tecla=='\x8' && pos>0) {
cad[pos-1]='\x0';
gotoxy(x+pos-1,y);
printf("");
}
} while (tecla!='\xD');
num=atoi(cad);
return num;
}

int Numeronegativo(int x, int y, int colorT, int colorF){
char tecla, cad[40];
int neg, num;
cad[0]='\x0';
do {
gotoxy(x,y);
printf("%s",cad);
setcolor(colorT);
setcolor(colorF);
tecla=getch();
neg=strlen(cad);
if (isdigit(tecla)) {
cad[neg]=tecla;
cad[neg-1]='\x0';
}
if (tecla=='\x8' && neg<0) {
cad[neg+1]='\x0';
gotoxy(x-neg+1,y);
printf("");
}
} while (tecla!='\xD');
num=atoi(cad);
return num;
}

float Numeroreal (int x, int y, int colorT, int colorF){
char tecla, cad[40],punto=0;
int pos;
float num;
cad[0]='\x0';
do {
gotoxy(x,y);
printf("%s",cad);
setcolor(colorT);
setcolor(colorF)
tecla=getch();
pos=strlen(cad);
if (isdigit(tecla) || tecla=='-' && pos==0) {
cad[pos]=tecla;
cad[pos+1]='\x0';
}
if (tecla=='.' && !punto) {
punto=1;
cad[pos]=tecla;
cad[pos+1]='\x0';
}
if (tecla=='\x8' && pos>0) {
punto=cad[pos-1]=='.'?0:punto;
cad[pos-1]='\x0';
gotoxy(x+pos-1,y);
printf(" ");
}
} while (tecla!='\xD');
num=atof(cad);
return num;

}



void dibujapantalla() {
/* Inicio del programa */
setcolor(WHITE);
rectangle(25,7,605,450);
rectangle(25,40,605,450);
rectangle(500,12,530,30);
rectangle(535,12,565,30);
rectangle(570,12,600,30);
outtextxy(512,20,"-");
outtextxy(547,20,"þ");
outtextxy(584,20,"X");
setcolor(YELLOW);
setbkcolor(BLUE);
outtextxy(50,20,"FILE");
outtextxy(49,21,"_");
outtextxy(120,20,"EDIT");
outtextxy(119,21,"_");
outtextxy(190,20,"SEARCH");
outtextxy(189,21,"_");
outtextxy(270,20,"RUN");
outtextxy(269,21,"_");
outtextxy(330,20,"COMPILE");
outtextxy(329,21,"_");
outtextxy(415,20,"DEBUG");
outtextxy(414,21,"_");
settextstyle(2,0,7);
outtextxy(100,75,"CAPTURA DE PRACTICA 1.4");
setfillstyle(6,MAGENTA);
bar(95,110,350,130);
rectangle(95,145,170,160);
rectangle(180,145,260,160);
setcolor(GREEN);
settextstyle(0,0,0);
outtextxy(110,150,"ACCEPT");
setcolor(RED);
outtextxy(200,150,"CANCEL");
}
void main(){
iniciagraficos();
clearviewport();
dibujapantalla();

int a=Numeropositivo(100,115,YELLOW,BLUE);
closegraph();
printf("%s",a);

int b=Numeronegativo(100,165,YELLOW,BLUE);
closegraph();
printf("%s",b);

int c=Numeroreal(100,225,YELLOW,BLUE);
closegraph();
printf("%s",c);

getch();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder