My C++ problems

I recently started to learn code and i decided to use C++, i am using dev c++ also. I did the 'hello world' code and it worked fine but i watched a tutorial on how to make a code that did averages and this is exactly the same as what he typed in on the tutorial i am about 99% sure. his worked, he was using dev c++ aswell and i had about 5 errors, can you tell me what i did wrong??


#include<iostream>

int main(void)
{

double dnumber1 = 0.0;
double dnumber2 = 0.0;
double dnumber3 = 0.0;

cout << "please enter 3 numbers " << end1;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

cout << "the average of the numbers is: " << end1 << end1;

system("pause");
return 0;

}
i noticed that you have <<end1<<end1 when it should be <<endl<<endl

use an L instead of 1
wasing is right. You are confusing the number 1 with the letter l.
Also, if you include iostream you must

either use std::cout, std::cin and std::endl

or type using namespace std; before your main function.

Oh, and daverage is not declared!

And my guess is that you wanted to write cout << "the average of the numbers is: " << daverage << endl;

instead of cout << "the average of the numbers is: " << endl << endl;
Last edited on
well I just saw it on youtube and he put << endl << endl I am pretty sure.
figjam wrote:
well I just saw it on youtube and he put << endl << endl I am pretty sure.

That's exactly what wasing pointed out. Incidentally, you don't need to write int main(void) because int main() will suffice.
Oh... and... please do not use system().
cin.ignore(); cin.ignore();
The first cin.ignore() clears out the newline that cin leaves in the stream. The second one pauses the program, as there is nothing to read.

-Albatross
What is this evil tutorial you are using? :S
A better question is "who puts a programming tutorial in video format?"
An even better questions is "who watches a programming tutorial in video format?"

What happened to the old-days of books and text?!
Paper is soon going to be obsolete, and books with paper are going to be obsolete even sooner.

That said, figjam, we recommend the tutorial on this very website. You'll have to do some reading, but it's worth it.
http://cplusplus.com/doc/tutorial/

-Albatross
http://www.youtube.com/user/reconnetworks is the guys videos that I watched
closed account (jwC5fSEw)
Paper is soon going to be obsolete, and books with paper are going to be obsolete even sooner.


How do you figure that?
Topic archived. No new replies allowed.