Hello, I am very new to the world of coding and I am trying to write a program that prompts the user to input five decimal numbers. The program should then add the five decimal numbers, convert the sum to the nearest integer, and print the result.
I am using Visual Studio 2015.
This is what I have right now and it doesn't work at all:
That should work... but it's not really practical... You have 5 separate variables to add 5 numbers. Remembering when I started looking at C++, I judge you to be about 2 days... I did a program very simular to this back then. If you spread your program out a little more, it would look more like this...
#include <iostream>
usingnamespace std;
int main()
{
cout << "Enter 5 decimals, pressing enter between each decimal:" << endl; // print message
int decimal, total=0; // Declare two variables @ zero
for (int i=0; i<5 ;i++) { //Count to 5 ( zero to 4) with a for loop
cout << "Please enter decimal then press enter "; // Ask nicely for input
cin >> decimal; // Get the value you want
total+=decimal; // adds the total every time they put in a number
} // makes the for loop add one and repeat as long as it's less than 5
cout << "Your total is " << total << endl; // Print your result
return 0; // End main
Don't get discouraged, Brighter days are in your future. I hopes that helps...