|
From: Mike S. <fre...@ho...> - 2002-01-09 05:29:00
|
How come in the following code, the second scanf is skipped?
int main()
{
/* Declare variables for main() */
int count;
float x, y;
char cmd, cont;
/* Use array symb[] for extended ASCII characters */
char symb[] = { 201, 187, 200, 188, 199, 182, 186, 205, 196 };
/* Infinite loop, using break; to stop */
while(1)
{
printf( "\n%c", symb[0] );
for ( count = 0; count < COL; count++ )
printf( "%c", symb[7] );
printf( "%c", symb[1] );
printf( "\n%c Calculator v1.02 %c",
symb[6], symb[6] );
printf( "\n%c", symb[4] );
for ( count = 0; count < COL; count++ )
printf( "%c", symb[8] );
printf( "%c", symb[5] );
printf( "\n%c This program is a small little DOS %c",
symb[6], symb[6] );
printf( "\n%c calculator. When entering commands, %c",
symb[6], symb[6] );
printf( "\n%c please enter them like the following, %c",
symb[6], symb[6] );
printf( "\n%c otherwise it will not work. %c",
symb[6], symb[6] );
printf( "\n%c Example: 12 + 13 %c",
symb[6], symb[6] );
printf( "\n%c Keep in mind that * is multiplication, %c",
symb[6], symb[6] );
printf( "\n%c and that / is division. %c",
symb[6], symb[6] );
printf( "\n%c", symb[2] );
for ( count = 0; count < COL; count++ )
printf( "%c", symb[7] );
printf( "%c", symb[3] );
printf( "\nEnter equation >> ");
scanf( "%f %c %f", &x, &cmd, &y );
/* Determine which operation to execute */
if ( cmd == '+' )
add( x, y );
else if ( cmd == '-' )
sub( x, y );
else if ( cmd == '*' )
mult( x, y );
else if ( cmd == '/' )
div( x, y );
else
printf( "\n%f %c %f is not a valid equation. ", x, cmd, y );
x = 0;
y = 0;
cmd = 0;
printf( "\nContinue? (Y/n) >> "); /* This scanf is skipped */
scanf( "%c", &cont );
/* If statement used to break infinite loop */
if ( cont == 'n' || cont == 'N' )
break;
else;
}
printf( "\n\n" );
system( "pause" );
return 0;
}
______________________________
Mike Shoup [freak901010/mike9010]
www.psxfanatics.com
|