Answer to Question #80905 in C++ for Tristan

Question #80905
Description of the Problem

Write a program that will ask the user to enter 3 character values, a letter, a number, and a symbol, such as B, 6, and #. Write the values in original form, decimal, hex, and octal notation. The output should be written in the format shown below.
Output:

letter = B number = 6 symbol = #

Decimal 66 54 35
Hex 42 36 23
Octal 102 66 43
1
Expert's answer
2018-09-17T11:17:08-0400
#include <iostream>
#include <ctype.h>
using namespace std;


int main()
{
char letter, number, symbol;
cout << "Enter a letter, a number and a symbol:" <<endl;
cin >> letter >> number >> symbol;
if (number < '0' || number > '9' || ! ispunct(symbol) || ! isalpha(letter) ) {
cout << "Wrong input." << endl;
return 0;
}
cout << "letter = " << letter << " number = " << number << " symbol = " <<
symbol << endl;
cout << "\nDecimal " << (int) letter << " " << (int) number << " " <<
(int) symbol << endl;
cout << hex << "Hex " << (int) letter << " " << (int) number << " " <<
(int) symbol << endl;
cout << oct << "Octal " << (int) letter << " " << (int) number << " " <<
(int) symbol << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS