answersLogoWhite

0


Best Answer

#include<iostream>

#include<string>

int main()

{

std::string input, invert;

bool ok = false;

while (!ok)

{

std::cout << "Enter a 5-digit binary number:";

std::getline (std::cin, input);

if (input.size()==5)

{

invert = input;

ok = true;

for (auto c = invert.begin(); c!=invert.end(); ++c)

{

switch (*c)

{

case ('1'): *c = '0'; break;

case ('0'): *c = '1'; break;

default: ok = false;

}

}

}

if (!ok)

{

std::cout << "Bad input\n";

invert.clear();

input.clear();

}

}

std::cout << "Input:\t" << input << std::endl;

std::cout << "Invert:\t" << invert << std::endl;

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program that takes a five digit binary number from user and prints the number with inverted bits?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

C program which accepts in order and preorder traversal outputs of a binary tree as input and prints the corresponding binary tree?

any body can help on this ?


Create a program which accepts a number not less than 10The program prints the reverse of the number?

ten


What is one tool for reverse engineering software and five features of that tool?

hexadecimal dumper, which prints or displays the binary numbers of a program in hexadecimal format.


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


How did menu's develop?

A restaurant prints it out using a special program


How do you write a c program that prints a box an oval an arrow and a diamond?

You first learn how to program in C.


What is the value of a 1935 D US 1 dollar silver certificate with an upside down serial number?

This is called an Inverted Overprint error and can be worth anywhere from $150 to $400 depending on the bill's condition. US paper bills are printed in multiple stages. An inverted overprint occurs when a sheet of bills is accidentally fed upside-down during the step that prints the serial numbers.


What is the phone number of the Ambers Originals And Prints in Chesterfield Virginia?

The phone number of the Ambers Originals And Prints is: 804-739-7466.


Write a program in c to convert binery number to hexa decimal number?

The question is somewhat ambiguous. If you have a value stored in a c variable, you can output it as a hexadecimal value by using a %x specification (printf("%x",z); prints z as a hex value. There is no specification (in most versions of c to input a binary number). If you mean convert a string which looks like a binary number to a string which looks like a hexadecimal number, then here is a code fragment char b[21]; // b holds binary string - 1 extra byte for null char h[6]; // h holds hex string - 1 extra byte for null char *p; int s; p=b; s=0; while (*p) { s = (s &lt;&lt; 1) + (*p-'0'); p++; } sprintf(h,"%x",s);


Dry run table in flow-chart?

/* my second program in C++ with more comments */ #include &lt;iostream&gt; using namespace std; int main () { cout &lt;&lt; "Hello World! "; // prints Hello World! cout &lt;&lt; "I'm a C++ program"; // prints I'm a C++ program return 0; }


Program in c to develop an algorithm that prints the n value of algorithm?

reymond rillera reymond rillera


Why MsgBox with string 000 prints e but 00 or 0000 are printed correctly Thank you ozcansyahoocom?

Your program is wrong.