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