Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HELP WITH THIS CODE! I need to make sure when i input the number 0 i get out 0x0. FOr some reason, I am getting

HELP WITH THIS CODE! I need to make sure when i input the number 0 i get out 0x0. FOr some reason, I am getting 0x. Please make sure that the code edit doesn't mess with the rest of the code.

#include using namespace std;

int main() { long int decnum, rem, quot; //variables declaration int i = 1, j, temp; //variables declaration char hexnumber[100]; //variables declaration

cout << "Enter a decimal number: "; cin >> decnum; //reading the decimal number quot = decnum; while (quot != 0) { temp = quot % 16; if (temp < 10) //for converting integer into character temp = temp + 48; else temp = temp + 55;

hexnumber[i++] = temp; quot = quot / 16; } cout << "Your number in hex is 0x"; for (j = i - 1; j > 0; j--) cout << hexnumber[j]; cout <<"."<< endl; return 0; }

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

Students also viewed these Databases questions

Question

What are the general types of interviews? Explain each.

Answered: 1 week ago