Question

Problem 3: Write a C++ program that prompts the user to enter an integer of any length (but not more than 8- digits), the proC++ please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

1 7 00 main.cpp 1 //Preprocessor directive to read and rite to the standard input/output stream 2 #include <iostream> 3 // Hemain.cpp 25 26 27 28 29 30 //Else set width(space) to the number else{ cout<<setw(last_digit); } // Print the last digit cout

Output:

X clang++-7 -pthread -std=c++17 -o main main.cpp ./main Enter an integer of any length. 9836472 ...Printing eachh digit in itх clang++-7 -pthread -std=c++17 -o main main.cpp } ./main Enter an integer of any length. 9274 ...Printing eachh digit in its

Summary:

1) Insert all the required headers (iostream, iomanip and using namespace std is optional as you call also use std inside the functions.)

2) Get the user input .

3) Repeat the while loop process till the user input has not digits left.

1) get the last digit

2) using setw() set the width/space as the last digit - If the digit is 0 setw() as 10 - ELse the last digit

3) Print the last digit

4) Set the user input with the last digit (Remove the last digit)

setw() - setw() in iomanip is used to set library width based on the parameter inside it.

Add a comment
Know the answer?
Add Answer to:
C++ please Problem 3: Write a C++ program that prompts the user to enter an integer...
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
  • In c++ please .. Write a program that prompts the user to enter a four-digit integer...

    In c++ please .. Write a program that prompts the user to enter a four-digit integer and displays the number in reverse order.

  • Write a Python program that prompts the user to enter integer values for each of two...

    Write a Python program that prompts the user to enter integer values for each of two lists. It then should displays whether the lists are of the same length, whether the elements in each list sum to the same value, and whether there are any values that occur in both lists.

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a program that prompts the user for a positive integer, n, and then prints a...

    Write a program that prompts the user for a positive integer, n, and then prints a following shape of stars using nested for loop, System.out.print(“*”);, and System.out.println();. Example1: Enter a positive integer: 3 * * * * * * * * * Example2: Enter a positive integer: 5 * * * * * * * * * * * * * * * * * * * * * * * * * JAVA LANGUAGE!!

  • write a c program for the above Write a program which prompts the user to enter...

    write a c program for the above Write a program which prompts the user to enter three integers (data type int) and then calculates the arithmetic average as a decimal number and prints the value with two decimal digits. If you have time also calculate and print the harmonic mean of the same numbers according to the following formula: 3. PT harmonic _mean-1 1 22x (Test with integer values of 4, 7, and 8. You may submit one program per...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • C++ Write a program that prompts the user to enter two positive integers: num1 and num2....

    C++ Write a program that prompts the user to enter two positive integers: num1 and num2. - Validate that num1 is less than num2 and that both numbers are positive. If any of these conditions are not met, allow the user to re-enter num1 and num2 until the input is determined valid. - For all integers from num1 through num2, print the word keyboard if the current integer is divisible by 2 and print the word mouse if the current...

  • write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to...

    write in C++ Exercise#1: Is it a Prime? Write a program that prompts the user to enter a positive integer in the range [100, 100000]. If the integer is not in the specified range the program prompts the user again. The program prints whether the integer is a prime number or not. Sample input/output nter an integer in the range [10e, 10eeee]: 39 nter an integer in the range [100, 100000]: 120453 Enter an integer in the range [10e, 10e000e]:...

  • Write a program that prompts the user to enter an integer, n , and then n...

    Write a program that prompts the user to enter an integer, n , and then n floating point numbers. As the numbers are read, the program will calculate the average of the negative numbers. In C language.

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