From the course: Secure Coding in C

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Confirming input

Challenge: Confirming input - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Challenge: Confirming input

(upbeat music) - [Instructor] So many people are winning the lottery that you've been asked to write a program to calculate the lottery winnings tax. The user inputs their total winnings, some huge dreamy number, and your code performs a number crunching on that value eventually spitting out the net after taxes. For this exercise assume the tax bite is 45%, meaning the user keeps 55% of their imaginary winnings. In the code obtain user input as a string, protect against null input, then massage the string to filter out any commas should the user type those characters in their winning amount. Convert the string into a floating point value ensuring that the value is legitimate, guard against negative winning values which wouldn't be taxed anyway and output the result after taxes. This challenge should take about 10 minutes to complete, longer if you had bugs, like I did, in my original attempt.

Contents