Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im trying to create a menu with several different options but my code is not running. the goal is for one menu option to convert

Im trying to create a menu with several different options but my code is not running. the goal is for one menu option to convert a decimal to any given base and any given base back to decimal, this is the code I have its is not running and Im not sure why! Could someone help please!! all in c++

#include #include #include #include using namespace std;

int main() { int choice; bool variableConvert = true; while (variableConvert != false){ cout > choice;

switch (choice) { case 1: cout = 0 && num 0) { res[index++] = reVal(inputNum % base); inputNum /= base; } res[index] = '\0'; // Reverse the result strev(res); return res; } // Driver Code int main() { int inputNum , base; cout > inputNum; cout > base; char res[100]; cout

return 0; }

break; case 2: cout > n; string s; while (n) { s += (n % 2) + '0'; n /= 2; } for (int i = s.size() - 1; i >= 0; i--) cout > choice; break; }

} return 0; }

image text in transcribedimage text in transcribed

/main.cpp:25:1: error: function definition is not allowed here q/ main.cpp:34:1: error: function definition is not allowed here q/ main.cpp:48:1: error: function definition is not allowed here q/ main.cpp:68:1: error: function definition is not allowed here 4 errors generated. make: [Makefile:10: main] Error 1 exit status 2 Please enter what you would like to do: a. Convert a number to decimal (enter a value \& given base) b. Convert a decimal to another base (enter a decimal value and a base) c. Convert a number from base1 to base2 (enter number, base1 and base2) q. Quit Enter your input value: FE Enter given base value: 16 The value FE in base 16 is 254 in decimal. please enter what you would like to do: a. Convert a number to decimal (enter a value \& given base) b. Convert a decimal to another base (enter a decimal value and a base) c. Convert a number from base1 to base2 (enter number, base1 and base2) q. Quit Enter your decimal value: 254 Enter resulting base value: 2 The decimal value 254 is 1111110 in base 2 Please enter what you would like to do: a. Convert a number to decimal (enter a value \& given base) b. Convert a decimal to another base (enter a decimal value and a base) c. Convert a number from base1 to base2 (enter number, base1 and base2) q. Quit Enter your input value: 11111100 Enter original base: 2 Enter output base: 16 The value 11111100 in base 2 is 252 in decimal. The value 11111100 is FC in base 16=FC

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions