Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can I please get help with this C program. This is the requirements. If in the requirements it mentions C++ please provide answer in C
Can I please get help with this C program. This is the requirements. If in the requirements it mentions C++ please provide answer in C as that is how I've written the code.
Modify the program Figure 2.10 (limit/num). Review the book section on the switch statement and the 'else if' clause Add new 'const' variables: base2, base3, base8, base10 and base16. Assign them the value the name implies Ask the user to enter a number base (2, 3, 8, 10 or 16) Follow the table below to output the correct values: base output ----- ------ 2 The first 4 powers of 2 3 The first 4 powers of 3 8 The first 4 powers of 8 10 The first 4 powers of 10 16 The first 4 powers of 16 Here is the kicker, DO NOT HARD CODE THE OUTPUT Duh..... We all know how to do this for 2: cout << " 1 2 4 8 " << endl; Instead use the proper const variable to calculate the power: cout << base2/base2 << " " << ... // you finish the calculations In other words, the program used to do this: 2 Binary 0..1 Now it should do this 2 1 2 4 8 If you run it again: 8 1 8 64 .... If you run it again: 16 1 16 .... Use 'else if' statements AND the 'const' variables to test the input. Use an 'else' at the very end and print an error messge when the input is NOT 2,3,8,10 or 16 AGAIN, DO NOT HARDCODE the values you print, calculate them
My Code:
#include#include int main() { const int limit = 100; const int base2 = 2; const int base3 = 3; const int base8 = 8; const int base10 = 10; const int base16 = 16; int num; printf("Enter the value of the base 2, 3, 8, 10, or 16: "); scanf("%d", &num); if (num == base2) { printf("Binary 0..1"); } else if (num == base3) { printf("Trinary 0..2"); } else if (num == base8) { printf("Octal 0..7"); } // checking if it is base10 i.e 10 else if (num == base10) { printf("Decimal 0..9"); } else if (num == base16) { printf("Hexidecimal 0..F"); } else { printf("Invalid Input"); } return (0); }
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