Question
Write program in C++
(20 points) Write a program that takes a positive number with a fractional part and rounds it to two decimal places. For example, 32.4851 would round to 32.49, and 32.4431 would round to 32.44 5.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>
#include<iomanip>

using namespace std;
int main() // main function
{

double number; // variable declaration

cout << setprecision(2) << fixed;

cout<<"Enter a fraction number: ";
cin>>number; // Accept number

cout<<"Number rounded two decimal as"<<number<<endl;

}

Output:

gcc version 4.6.3 Enter a fraction number: 32.4851 Number rounded two decimal as32.49

Add a comment
Know the answer?
Add Answer to:
Write program in C++ (20 points) Write a program that takes a positive number with a...
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
  • Write a C program that takes a positive integer n as input and prints all the...

    Write a C program that takes a positive integer n as input and prints all the prime numbers from 1 to n. Sample Input/Output 1: Enter your n: 20 Prime number(s) from 1 to 20 : 2 3 5 7 11 13 17 19 Sample Input/Output 2: Enter your n:2Prime number(s) from 1 to 2 : 2

  • 29. (20 points) Write the complete C++ program that implements the following program, as if you...

    29. (20 points) Write the complete C++ program that implements the following program, as if you were turning this in for homework. Your program should have a commented header (your name, etc), comments within the program and a well-built display for the output. Don't forget the pre-processor commands Define an array called nums with a maximum of 20 integers, and fill the array with numbers, recei the keyboard (prompt for the numbers.) In this program, exactly 20 integers will be...

  • Write the following code in C. Write a program that takes a positive integer and prints...

    Write the following code in C. Write a program that takes a positive integer and prints that many stars These are sample outputs. Enter the number of stars: 9 Enter the number of stars: 4 Enter the number of stars: -3 Invalid input!

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • In C++ Make a program that takes a positive integer 'n' and write an n x...

    In C++ Make a program that takes a positive integer 'n' and write an n x n matrix whose entries are listed as snail Example: (See picture) for n=6 Ej. Para n-6 2 2 2 20 21 22 23 24 7 19 32 33 34 258 18 31 36 35 26 9 17 30 29 28 27 10 16 15 14 13 12 11

  • Kaprekar C++ program a. Write a c++  code that takes any number between 0 and 9999 as...

    Kaprekar C++ program a. Write a c++  code that takes any number between 0 and 9999 as an input value, and returns the number of iterations it takes that number to reach 6174. Also, it needs to indicate if the number does not converge to 6174. Run the program with three different numbers of your choosing to show that it works. b. Write a second c++ code using the first. However, this new program will calculate how many iterations it takes...

  • Python: Write a function subsetSum() that takes as input a list of positive number and a...

    Python: Write a function subsetSum() that takes as input a list of positive number and a positive number target. The function returns True if there are three numbers in the list that add up to the target. For example, the list [5, 4, 10, 20, 15, 19] and targert 38, then True is returned since 4 + 15 + 19 = 38. However, the list [5, 4, 10, 20, 15, 19] and target 5 returns False. >>> subsetSum([5, 4, 10,...

  • Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a...

    Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray (), which takes two arguments and reverses the...

  • Write a program that takes as input a positive real number s and a positive real...

    Write a program that takes as input a positive real number s and a positive real number E and outputs the approximate value of Vs to within the tolerance E. In other words, the output of your program should be a number s' such that Is SIS E. (Thus the distance" between the output s' and the correct answer Vs should be at most E.) Your program should implement a very old algorithm for approximating the square root of numbers,...

  • In Python, write a program that asks the user for a positive integer number. If the...

    In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686

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