This is for a c++ program, please read the specifications carefully to make sure
ID: 645934 • Letter: T
Question
This is for a c++ program, please read the specifications carefully to make sure it does what it is supposed to do. This is for a 100 level class so no need to get over complicated. Thanks
Specifications: The little calculator processes several lines of character input from the terminal or from a file (your choice). On each line, it does a single integer arithmetic computation, or generates an error message. A correct line of input consists of an integer, an operator, and another integer, with zero or more blanks between each token. Programmer Option: The little calculator can process input character by character, or by reading entire line in as a string. The little calculator accepts as correct the integer operators *, /, +, -, %. The little calculator would evaluate as correct a file containing the following:
123 * 12<ret>
32000 - 500<ret>
45%20<ret>
32000 + 767<ret>
<ret>indicates Enter key.
For the last line above the little calculator would output: answer is 32767. The little calculator needs to catch three types of errors. The following three lines would be recognized as containing errors respectively:
Explanation / Answer
#include <stdio.h>
int main()
{
unsigned int number;
int count = 0;
printf("Enter the unsigned integer: ");
scanf("%d", &number);
while (number != 0)
{
if ((number & 1) == 1)
count++;
number = number >> 1;
}
printf("number of one's are : %d ", count); return 0
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.