Answer to Question #237239 in C++ for xuu

Question #237239

4. Write a C++ program that

1) prompts the user to input 3 decimal numbers (with a fraction part)

2) Prints the three decimal numbers.

3) Converts each decimal number to the nearest integer.

4) Prints the three converted numbers.


1
Expert's answer
2021-09-15T02:29:01-0400
#include <iostream>
#include <cmath>


using namespace std;


int main()
{
    double numbers1, numbers2, numbers3;
    int int1, int2, int3;
    //1) prompts the user to input 3 decimal numbers (with a fraction part)
    cout << "Please enter 3 decimal numbers: \n";
    cin >> numbers1 >> numbers2 >> numbers3;
	//2) Prints the three decimal numbers.
    cout<<endl << numbers1 << " " << numbers2 << " " << numbers3<<endl;
    //3) Converts each decimal number to the nearest integer.
    int1 = round(numbers1);
    int2 = round(numbers2);
    int3 = round(numbers3);
    //4) Prints the three converted numbers.
	cout<<endl<<"The three converted numbers: "<<endl;
	cout << int1 << " " << int2 << " " << int3<<endl;


    return 0;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS