Question: write a C + + program that asks the user to enter an integer. The program should read the input in as a string and
write a C program that asks the user to enter an integer. The program should read the input in as a string and stores it in a string variable. It will then check to make sure the input consists of only digits. If the input contains only digits, the program should calculate and display the square of the number. If the number contains anything other than digits, it should print a message telling the user how many nondigit characters they entered. Include in your program the following functions:
isNumber accepts a string as it's only argument. Returns true if all the characters in the string are digits, false otherwise. Does not interact with the user in any way.
countNonDigits accepts a string as it's only argument. Counts and returns the number of nondigit characters in the string. Does not interact with the user in any way.
Use isNumber to determine if the input from the user consists of only digits as part of an if statement test expression. Use countNonDigits to get the total number of nondigits in the string to display to the user if the input contains anything other than digits. A point submission will:
correctly reading user input as a string Max points
correct implementation of function isNumber Max points
correct implementation of function countNonDigits Max points
correct implementation of main asking users for input, calling functions, displaying appropriate output: points
Following submission instructions Max points
A minimum point penalty will be incurred for using code not covered in the course.
If your source does not compile, it will automatically receive points.
Other deductions may occur according to guidelines in the syllabus.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
