Please Get Help C Program Requirements Requirements Mentions C Please Provide Answer C Ve Q43864945
Can I please get help with this C program. This is therequirements. If in the requirements it mentions C++ please provideanswer 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’ clauseAdd new ‘const’ variables: base2, base3, base8, base10 and base16. Assign them the value the name impliesAsk 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 16Here is the kicker, DO NOT HARD CODE THE OUTPUTDuh….. 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:2Binary 0..1Now it should do this 21 2 4 8If you run it again:81 8 64 ….If you run it again:161 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 16AGAIN, DO NOT HARDCODE the values you print, calculate them
My Code:
#include <stdio.h> #include <stdlib.h> 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); }
Expert Answer
Answer to Can I please get help with this C program. This is the requirements. If in the requirements it mentions C++ please prov…
OR