Question: Write a C++ program that prompts a user to enter a binary number (Os and 1s). Your program then checks that it is indeed a

 Write a C++ program that prompts a user to enter a

Write a C++ program that prompts a user to enter a binary number (Os and 1s). Your program then checks that it is indeed a binary number, meaning that it contains only 0s and 1s. If it is not the case, your program should print a message that the number is not a valid binary number. If it is a valid binary number then your program should count how many 1s are in the word and output the count. Note: a. You can use any type of loop you like b. The number should be read into a String variable. Following are two sample output screens; first one is an example of a valid binary number entered by user, while the second example illustrates an example where the user entered an invalid binary number. Your output does not need to be formatted in exactly the same way. Just make sure the required information appears. Your program must work for any binary or non binary numbers entered by the user, not just the ones in the samples below. C:Windows system321cmd.exe lease enter a binary nunber and I will tell you how nany 1s there are: 01010 here are 3 1s in the binary number 18181e0 C:Windows system321cmd.exe Please enter a binary nunber and I will tell you how nany 1s there are: 1012011 That is not a valid binary number

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!