Answer to Question #318150 in C++ for alex

Question #318150

Write a C++ program that

1) prompts the user to input 5 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
2022-03-25T15:11:32-0400
#include <iostream>
using namespace std;


int main() {
    double d1, d2, d3, d4, d5;


    cout << "Enter five decimal numbers: ";
    cin >> d1 >> d2 >> d3;


    cout << "First three numbers are " << d1 << " " 
         << d2 << " " << d3 << endl;
    
    int i1, i2, i3, i4, i5;
    i1 = static_cast<int>(d1+0.5);
    i2 = static_cast<int>(d2+0.5);
    i3 = static_cast<int>(d3+0.5);
    i4 = static_cast<int>(d4+0.5);
    i5 = static_cast<int>(d5+0.5);


    cout << i1 << " " << i2 << " " << i3 << 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