Question

Flowchart and pseudocode for a program that takes a user input consisting of an integer number...

Flowchart and pseudocode for a program that takes a user input consisting of an integer number between 0 and 99 and outputs its conversion as binary. For example, if a user enters 25, the output should be 11001.

The program should also validate the input and continuously ask for a new input if the number is not within the appropriate range of values.

Additional instructions:

  • check that the user enters a number between 0 and 99.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pseudocode:

start

i<-1

base2 <- 0

print Enter an integer between 0 and 99 to convert binary

Accept integer

while(integer>99||integer<0) do

print Invalid input!! Enter an integer between 0 and 99 to convert binary

Accept integer

end while

while (integer!=0) do

rem <-integer%2

integer <- integer / 2

base2 <- base2 + rem*i

i <- i*10

end while

print Binary number

end program

Code to verify the correctness of the above pseudocode:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

int integer,rem;

long long i=1,base2 = 0;

cout << "Enter an integer between 0 and 99 to convert binary: ";

cin >> integer; // Accept the integer

while(integer>99||integer<0)

{

cout << "Invalid input!!Enter an integer between 0 and 99 to convert binary: ";

cin >> integer; // Accept the integer

}

while (integer!=0)

{

rem = integer%2; // calculate remainder

integer /= 2; // divide integer by 2

base2 += rem*i; //Add remainder*i value to base 2

i *= 10;

}

cout<< "Binary number = "<<base2<<endl ; // print binary number

return 0;

}

Output:

Please Rate My Answer

Add a comment
Know the answer?
Add Answer to:
Flowchart and pseudocode for a program that takes a user input consisting of an integer number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT