Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Inputting Decimal- Octal and Hexadecimal Values using C++ programming

Write a program to test the inputting of integer values in decimal, octal and hexadecimal formats. Output each integer read by the program in all three formats.

Answer:



#include <iostream> 
#include <iomanip> 
#include <string>
using namespace std;

void show( const string message )
{
   int integer; // holds values input by user

   // prompt user to enter data in decimal format
   cout << "\n" << message; cin >> integer; // store data in integer
   
   // display integer in decimal, octal and hexadecimal format
   cout << showbase << "As a decimal number "  << dec 
      << integer << "\nAs an octal number " << oct << integer
      << "\nAs a hexadecimal number " << hex << integer << endl; } // end function show int main() { show( "Enter an integer: " ); cin >> oct;
   show( "Enter an integer in octal format: " );
   cin >> hex;
   show( "Enter an integer in hexadecimal format: " );
} // end main

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!