Reputation: 5
How do I quote an integer that the user inputted along with the result. Example, I'm trying to make this code print, The number "12" in binary format is "1100"
My code;
#include <iostream>
using namespace std;
void decimalToBinary();
int main()
{
decimalToBinary();
return 0;
}
void decimalToBinary()
{
int array[32];
int number, index;
cout << "Enter a number to convert to binary: ";
cin>>number;
cout << endl;
cout << "The number " << number << " in binary format is ";
for(index=0; number>0; index++)
{
array[index]=number%2;
number= number/2;
}
for(index=index-1 ;index>=0 ;index--)
{
cout << array[index];
}
}
Upvotes: 0
Views: 81
Reputation: 117
You need to put a \ (escape sequence, the same method used for \n, or \t)to show that the quotes are to be ignored:
cout << "The number \" " << number << " \" in binary format is ";
Upvotes: 4