Answer to Question #67252 in C++ for Mian Saqlain

Question #67252
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++;
1
Expert's answer
2017-04-11T01:53:07-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS