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.
#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;
}
Comments
Leave a comment