Question: 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,

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  

This is my code so far.

#include #include //for formatting

using namespace std; int main(){ int n; //ask user to enter a number cout>n; cout =5 || n

//if out of range cout

//if in range loo from 1 to that number for(int i=1; i

return 0;}

Here are expected results.

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

1. Compare output Input 5 Please enter a number (5 to 30) 5 Your output Please follow the directions! Please enter a number (5 to 30) 5 1/1 is 1.00 1/2 is 0.50 J Expected output 1/3 is 0.33 1/4 is 0.25 1/5 is 0.20 2. Compare output Input 3 Please enter a number (5 to 30) 4 Your output Please follow the directions 3. Compare output Input 31 Please enter a number (5 to 30) 31 Your output Please follow the directions

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!