Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can i get help with this C program requirement. Modify the program Figure 2.13 (letter/while). Create a variable at the top of your code named
Can i get help with this C program requirement.
Modify the program Figure 2.13 (letter/while). Create a variable at the top of your code named power2 and assign it the value 8 Create a variable at the top of your code named result and assign it the value 0 Ask the user to enter FOUR 1's and 0's followed by a '*' In the loop, when the letter is '1' add power2 to result and store it back into result In the loop, change power2 to be the next lower power of 2 After the loop do a cout to print the result and explain it is decimal In other words, the program used to do this: 0101* 0101 Now it should do this 0101* That is 5 in decimal If you run it again: 1010* That is 10 in decimal If you run it again: 0111* That is 7 in decimal In other words, you just wrote a binary to decimal converter.
Here is my code:
#include
int main() { char letter; printf("Please enter FOUR 1's and 0's and add * at the end; "); scanf("%c", &letter); while(letter != '*'){ printf("%c* power2 =", letter); printf(" "); scanf("%c", &letter); }
return (0); }
Thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started