IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CLoops : Fuel Tank Program
<04.03>
/* The fuel tank program */
#include <stdio.h> #define CAPACITY 5000 /* fuel tank capacity (liters) */ int main (void) { double supply, pumped; /* all in liters */ /* ask user for initial supply already in tank */ printf ("Enter the the initial supply: "); scanf ("%lf", &supply); /* the program loops until supply falls below 10% */ while (supply > CAPACITY * 0.10) { /* ask user for quantity removed or delivered */ printf ("\nEnter the amount delivered(+)/removed(-): "); scanf ("%lf", &pumped); supply = supply + pumped; /* test so that you don't pump more when tank is empty */ if (supply < 0.0) supply = 0.0; /* test so that you don't fill more when tank is full */ if (supply > CAPACITY) supply = CAPACITY; } printf ("\nSupply below 10%% (%.2lf l remaining)\n", supply); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter the the initial supply: 2000 Enter the amount delivered(+)/removed(-): -900 Enter the amount delivered(+)/removed(-): 1100 Enter the amount delivered(+)/removed(-): -1400 Enter the amount delivered(+)/removed(-): -200 Enter the amount delivered(+)/removed(-): -250 Supply below 10% (350.00 l remaining)
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland