C++ Keyboard

Im having trouble with this problem.

I have to write a C++ program that reads in 10 numbers from the keyboard and then add them together. Then, finally prints its total.

Can someone help? Where do I begin from?
Well...you read the numbers one by one into an array of numbers, then traverse the array to sum it up, then print the sum.
Try prompting the user for each of the ten numbers. Store each of them in their own variable. Then finally, add them all up and print the sum.
suagbor: please tell us what you are allowed to use? Do you know arrays and loops?

I would recommend you to look into some beginner tutorials, where they explain how a program is structed. I will tell you only what roughly need to know:

A executable program always needs a 'main function' in C++. So these 4 lines are already valid code and compilable sourcecode.

1
2
3
4
int main()
{
    return 0;
}


Now lets think what you need for input. To print something out or read in you certainly need some 'objects' like cin and cout (pronounced: see-in, see-out) Here i a little sample code you can type into your IDE or your most trustworthy texteditor. I hope you know how to compile programs.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream> // here we get our objects cin and cout from. this makes them available
using namepsace std; // some technical reason to write this here, dont bother with this

int main()
{
    int a;

    cout << "Hey i write something to console.\nType some integer:";
    cin >> a;
    cout << "Wow! " << a << " is a really great number!\n";
    return 0;
}


Questions?

Yours Maikel
Last edited on
@trostemd,
It would be better to use an array as Corpus suggested.
Last edited on
Don't double post. Your question should be posted exactly once across this entire website and once only.
There are a vast number of means to do this problem. The one with the smallest memory footprint, and the one that I would probably prefer in this case due to minimum code typing, is to create a for loop that executes ten times, and each time, get a number (to the same variable). After getting another number, add it onto a total (compound assignment operator, look it up if you don't recognize +=) and go around again.
Topic archived. No new replies allowed.