Question: How do I round up the solution? Question: Ask the user for a number between 5 and 30. For each number between 1 and the

How do I round up the solution?

Question:

Ask the user for a number between 5 and 30. For each number between 1 and the number entered, display the value 1/that number, as a ratio and a decimal value. Round up on .005 and above. For example:

Please enter a number (5 to 30): 5 1/1 is 1.00 1/2 is 0.50 1/3 is 0.33 1/4 is 0.25 1/5 is 0.20 

Use the following format specifiers to get the precision of the output to match:

 cout.setf(ios::fixed, ios::floatfield); cout.precision(2); cout  

Current Code:

#include #include //for formatting

using namespace std; int main(){ int n; cout>n; cout 30){ cout

cout

Outputs:

How do I round up the solution? Question: Ask the user for

5. Compare output 15 nput Please enter a number (5 to 30) 15 1/1 is 1.00 1/2 is 50 1/3 is 0.33 1/4 is 0.25 1/5 is 0.20 1/6 is 0.17 1/7 is 0.14 Your output 1/8 is 0.12 1/9 is 0.11 1/10 is 0.10 1/11 is 0.09 1/12 is 0.08 1/13 is 0.08 1/14 is 0.07 1/15 is 0.07 Please enter a number (5 to 30) 15 1/1 is 1.00 1/2 is 50 1/3 is 0.33 1/4 is 0.25 1/5 is 0.20 1/6 is 0.17 1/7 is 0.14 Expected output 1/8 is 0.13 1/9 is 0.11 1/10 is 0.10 1/11 is 0.09 1/12 is 0.08 1/13 is 0.08 1/14 is 0.07 1/15 is 0.07

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!