Keyboard

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 do this for me?
We just answered this in Beginners forum.
Well you made it seem simple, but dont we have to use different functions to get this to work?
Try this off the top of my head

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>
using namespace std;

int main()
{ 
double tempHolder, sum = 0.0;       
vector<double> list;
       for(int i = 0; i < 10; i++)
       {
               cin >> tempHolder;
               list.push_back(tempHolder);
       }   
       
       for(i = 0; i < 10; i++)
      {
             sum += list[i];
      }

      cout << sum << endl;
return 0;
}  


I know this may be advanced for what you are doing. You seem to me like a beginner, so this code will either make your teacher think you are a genius, or that you got this from somewhere. Enjoy :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

int main()
{
	double sum = 0.0;

	for (int i = 0; i < 10; i++) {
		double input;

		cout << "type in number " << i << "#: ";
		cin >> input;
		sum += input;
	}

	cout << "Sum is " << sum << endl;
	return 0;
}
Last edited on
Doesn't anyone have the good sense to ask a question just once?
Bunch of little kids standing around going "Dad. Dad. Dad. Dad. Dad..."

I'm deleting my reply in the other forum.
Technically this is a different question in that he's now asking someone to do it for him rather than asking for help.

Kind of sad, actually.
What's worse is that he's getting it.

Don't do his homework for him you fools!

@dcfjoe,
Why would that code make anyone think anyone is a genius?
Exaggeration my dear Chrisname. Or so I presume it may be.
Inflated egos is one of the most common aflictions in the programming world.

It is very good for a raw beginner.
It is very bad for anyone who [edit] has been programming for a little while [/edit].

(I still don't know why everyone automatically pulls out their arrays and vectors for questions like this...)
Last edited on
Can someone do this for me?
Hm. They're not even trying anymore, are they?

Since this topic is worthless anyway, allow me to derail.
I actually was called "a genius" by a teacher once in elementary. She was giving a complicated question -- possibly a sort of brainteaser -- and I, realizing this, thought "what the hell. I'll do it in my head." I can't quite remember how long it took me, but it must have been 5-10 seconds.
Topic archived. No new replies allowed.