O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code Sample 5.3: The PercentageCalculator Program

As a way of covering everything you have learned thus far, including console input and output, Code Sample 5.3 contains a simple program that calculates the percentage based on a maximum and partial value. So if you were to enter 100 and 10, the result would be 10%.

Before reading the code, you might like to think about which features of the C language are used to create the program. You need a way to:

  • Read in values

  • Store the values

  • Perform the calculation

  • Display the result

You might not like to restrict the users to small values, so you should use the largest integers possible to store data. The percentage is likely to be between 0 and 100, but it could also be a floating-point value, so that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required