Question: C Programming Write a program that prompts the user to enter two positive whole numbers as strings! Create a function that validates the input and

C Programming

Write a program that prompts the user to enter two positive whole numbers as strings!

  • Create a function that validates the input and returns true if all chars in the string are digits. Call the function from the main and prompt the user to re-enter as long as invalid input was entered.
  • Create a second function that converts the string to an int and returns it. Use a loop to iterate over each char in the string. You can convert a char c to an int by subtracting the char 0 from it: int num = (int)ch - '0'; Add the digit to a result variable and multiply the result with each iteration by 10, for example: 4127 can be split up as 4 * 1000 + 1 * 100 + 2 * 10 + 7 * 1

The program then converts both strings to integers and computes and prints out the sum.

Hints: You may use the isdigit(x) function provided by

WARNING: If you're program does not execute due to syntax errors, you will lose at least 50% of total points.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!