I'm taking a C class, and we use a POS statement to position and display
things on the screen. This works fine at the school, however, when I try to
get it to work at home, it comes up weird like:
[10;5f---[Time System]---[12;5f[1] Enter a Minute-Time.[13;5f[2] Quit.[14;5f
Enter a choice [1-2]: [2J[10;5f---[Time System]---[12;5f[1] Enter a Minute-Ti
me.[13;5f[2] Quit.[14;5fEnter a choice [1-2]:
I know this works because this is a program that I wrote in class. So I think
it has something to do with my ansi.sys file.
I'm running windows ME, and the ones at school we use windows XP.
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define CLS printf("\x1B[2J")
#define POS(u,v) printf("\x1B[%d;%df", u, v)
#define LOCATE printf("\x1B[s")
#define RESTORE printf("\x1B[u")
#define EOL printf("\x1B[K")
#define PAUSE getch()
#define HOUR 60
void menu();
void choice();
void compute();
void quit();
void main ()
{
menu();
choice();
quit();
return;
}
void menu()
{
POS(10, 5);
printf("---[Time System]---");
POS(12, 5);
printf("[1] Enter a Minute-Time.");
POS(13, 5);
printf("[2] Quit.");
POS(14, 5);
printf("Enter a choice [1-2]: ");
return;
}
void choice()
{
int run = 1, choice;
while (run == 1)
{
CLS;
menu();
scanf("%d", &choice);
switch (choice)
{
default:
POS(16, 5);
printf("That is an incorrect choice.");
POS(17, 5);
printf("[ Enter ]");
PAUSE;
break;
case 1:
compute();
break;
case 2:
quit();
run = 0;
break;
}
}
return;
}
void compute()
{
int minutes;
float time, fminute;
CLS;
POS(10, 10);
printf("Enter minutes from 1 and 10,000 |>");
scanf("%d", &minutes);
if(minutes < 1 || minutes > 10,000)
{
CLS;
POS(15, 15);
printf("Enter a value between 1 and 10,000");
PAUSE;
return;
}
time = minutes / HOUR;
fminute = minutes % HOUR;
POS(15, 10);
printf("[ Minutes ] %d", minutes);
POS(17, 10);
printf("[ Hours ] %2.2f", time);
POS(19, 10);
printf("[ Minutes ] %2.2f", fminute);
PAUSE;
POS(20, 10);
printf("[ Enter ]");
return;
}
void quit()
{
CLS;
POS(20, 20);
printf("Quitting.....have a NICE DAY.");
PAUSE;
exit(0);
}