Code:
#include <stdio.h>
int main(void)
{
int start_head, calc_1, calc_2, start_cyl, end_cyl, end_head;
printf ("Please enter the starting cylinder: ");
scanf ("%x", &start_cyl);
getchar();
printf ("Please enter the starting head: ");
scanf ("%x", &start_head);
getchar();
while (start_head < 0x0 || start_head > 0xe)
{
printf ("Invalid input, please re-enter the starting head: ");
scanf ("%x", &start_head);
getchar ();
}
printf ("Please enter the ending cylinder: ");
scanf ("%x", &end_cyl);
getchar();
printf ("Please enter the ending head: ");
scanf ("%x", &end_head);
getchar();
while (end_head < 0x0 || end_head > 0xe)
{
printf ("Invalid input, please re-enter the ending head: ");
scanf ("%x", &end_head);
getchar();
}
calc_1 = (start_cyl * 0x80 * 0xf) + (start_head * 0x80);
calc_2 = (end_cyl * 0x80 * 0xf) + (end_head * 0x80);
printf ("The starting block is: %d\n", calc_1);
printf ("The max extent is: %d\n", calc_2);
getchar();
return 0;
}
OK, here is the last working version. I'm very new to this so go easy lol. Eventually I'd like to test the start_cyl to make sure it's 5 digits or less and all 5 digits are valid hex numbers (0-f). For now I'd like to start with testing start_head to verify it is only 1 digit and between 0 and e. Now the test for the start_head and end_head work, but if you issue say rr it prints the error twice and so on.