Question #27223

Question 6: Write a Program that prompts the user to input five decimal numbers in one Line Separated with Space. The program should then add the five decimal numbers, convert the sum to the nearest integer, and print the result (5 points)
Sample Output
Enter the Five Decimal Numbers: 25 3.4 68.3 9 4.1
The Sum of these Decimal Numbers is = 109.8
Number Round to = 110

Expert's answer

#include <iostream>

#include <string>

#include <conio.h>

using namespace std;

//main function

int main()

{

string FivedecimalNumbers;//input numbers

double Sum=0;//variable for sum

int NumberRound;

cout<<"Enter the Five Decimal Numbers: ";

cin >> FivedecimalNumbers;//input FivedecimalNumbers

//calculate sum

for(int i=0;i<FivedecimalNumbers.length();i++){

Sum+=(double)FivedecimalNumbers[i];

}

//show rsult

cout<<"The Sum of these Decimal Numbers is = "<<Sum;

NumberRound=(int)Sum;

cout<<"Number Round to = "<<NumberRound;//show Number

Round

getch();

return 0;

}

#include <string>

#include <conio.h>

using namespace std;

//main function

int main()

{

string FivedecimalNumbers;//input numbers

double Sum=0;//variable for sum

int NumberRound;

cout<<"Enter the Five Decimal Numbers: ";

cin >> FivedecimalNumbers;//input FivedecimalNumbers

//calculate sum

for(int i=0;i<FivedecimalNumbers.length();i++){

Sum+=(double)FivedecimalNumbers[i];

}

//show rsult

cout<<"The Sum of these Decimal Numbers is = "<<Sum;

NumberRound=(int)Sum;

cout<<"Number Round to = "<<NumberRound;//show Number

Round

getch();

return 0;

}

## Comments

## Leave a comment