/* ------------------------------------------------------------------------ // Figure 4.25: Ramp up and down. // Output a series of voltage values that ramp up from 0 to some // maximum and then back down to 0 again in one-volt increments. // ------------------------------------------------------------------------ */ #include #define LOWER 5 #define UPPER 10 void main( void ) { int vmax; /* Voltage maximum of ramp */ int volts; /* Current voltage value */ printf( "\n Enter the maximum voltage for the ramp: " ); scanf( "%i", &vmax ); while (vmax < LOWER || vmax > UPPER) { /* Check for valid input. */ printf( "\n Input=%i is not between %i and %i." "\n Try again. Please enter a voltage: ", vmax, LOWER, UPPER ); scanf( "%i", &vmax ); } puts( "\n" ); volts = 0; /* We will start and end at zero volts. */ while (volts < vmax) { /* Ramp up */ printf( " Voltage = %i\n", volts ); volts++; } puts( "\n" ); /* Voltage is now at maximum. */ while (volts > 0) { /* Ramp down */ printf( " Voltage = %i\n", volts ); --volts; } /* Voltage is back down to 0. */ }