63 125
Assignments Done
99%
Successfully Done
In July 2018

Answer to Question #61887 in C++ for James Kulesa

Question #61887
I have assignment where I need to prompt user for an integer to convert to binary, oct, hex.

The prompt is suppose to be enter Integer to convert or DONE to stop. how do you do this being that the integer and "DONE" are of different types.
Expert's answer
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main()
{
char answer[10];

cout << "Enter Integer to convert or DONE to stop:" << endl;
cin>>answer;
if (strcmp(answer, "DONE")!=0){
int number;
number=atoi(answer);
cout<<"\nOct:"<<oct<<number<<"\nHex:"<<hex<<number;

char binary[80];
itoa(number, binary, 2);
cout<<"\nBinary:"<<binary;
}

cout<<endl;
return 0;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions