Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // Enter 5 numbers and
- // display the numbers and the sum.
- int main()
- {
- int input[5] = { 0, 0, 0, 0, 0 }; // The values entered.
- int sum = 0; // The sum of the values entered
- cout << "Enter 5 numbers, one at a time." << endl;
- for (int i = 0; i < 5; i++) // Five times,
- {
- cout << "Enter a number: ";
- cin >> input[i]; // Store the number.
- sum += input[i]; // Add the number to the total.
- }
- cout << endl; // Blank line.
- cout << "The sum of\n";
- for (int j = 0; j < 5; j++) // Five times,
- {
- cout << input[j];
- if (j < 4)
- {
- cout << " + ";
- }
- }
- cout << " is " << sum << endl; // Display the sum.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement