448,821 Members | 1,513 Online
Need help? Post your question and get tips & solutions from a community of 448,821 IT Pros & Developers. It's quick & easy.

# Help writing a C++ program to do decimal-binary number conversions.

 P: 2 This is what the assignment says to do: Write a C++ program to do decimal-binary number conversions. The program gives the user a choice of conversion type (binary to decimal or decimal to binary). After the user makes a selection and enters an original datum to convert, the program should check if the input is valid. The user will be asked to reenter data until the input is acceptable. Finally, the original number and the converted form are both shown on the screen. The main( ) function should be placed at the beginning of your program. This is what i have but the teacher says i need to correct it, i need to programm it so the user chooses to do either the decimal to binary or binary to decimal and then display the results: Expand|Select|Wrap|Line Numbers #include  #include  #include  using namespace std;   int main() {   // Conver a decimal number to binary   int dec, len; string bin;   // Ask user to enter a decimal numner   cout << "Please enter a decimal number:" << endl; cin >> dec; bin = "";   while (dec != 0) { if (dec % 2 == 0) bin.insert(0, "0"); else bin.insert(0, "1"); dec = dec / 2; }   // Output decimal number to binary number   cout << "The equivalent binary number is: " << bin << endl << endl;   // Convert a binary number to decimal   double deci;   // Ask user to enter a binary number   cout << "Enter a binary number:" << endl; cin >> bin;   cout << bin << endl;   len = (int) bin.length();   cout << len << endl; deci = 0; for (int i=0; i