Write a program that does the following: a. Prompts the user to input five decimal numbers. b. Prints the five decimal numbers. c. Converts each decimal number to the nearest integer.
Please do it in c++;
#include<iostream>
using namespace std;
int main()
{
const size_t n = 5;
double data[n];
cout << "Enter 5 numbers:\n";
for (size_t i = 0; i < n; i++)
{
cout << "number[ " << (i + 1) << "] = ";
cin >> data[i];
}
cout << "U`ve entered 5 numbers: ";
for (size_t i = 0; i < n; i++)
{
cout << "number[ " << (i + 1) << "] = " << data[i]<<" ";
}
int converted_data[n];
for (size_t i = 0; i < n; i++)
{
converted_data[i] = round(data[i]);
}
cout << "\nConverted 5 numbers: ";
for (size_t i = 0; i < n; i++)
{
cout << "number[ " << (i + 1) << "] = " << converted_data[i] << " ";
}
system("pause");
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!
Learn more about our help with Assignments:
C++