How can i create this C++ program.

Im new in C++ programming so i dont know the required syntax.
The program is suposed to calculate the addiction S=1^2+2^2+3^2+...+(2n+1)^2
Use the function pow() to raise N to a power.
http://cplusplus.com/reference/clibrary/cmath/pow/
this was helpfull, but i still dont understand a thing.
i saw many times that "\n" is used in some programms.
my question is, what does is change ?
is there any difference if i dont use it ?
"\n" is a newline escape character:

 
cout <<"This is a line \nThis is another line";

output:

This is a line
This is another line


Without \n output would be

This is a line This is another line
Last edited on
+1 Null

Hmmm.. how much C++ do you know?
so is exactly like using this:
1
2
3
4
5
6
7
8
#include<iostream>
int main()
{
cout<<"This is a line"<<endl;
cout<<"This is another line";
system("pause");
return 0;
}

and the output is same just we use 1 row instead of 2. :D
thx. now i finally understoot it.

P.S.: "\n" can be used with "<iostream>" ?
Last edited on
Sure, \n can be use without <iostream> but you cannot use std::cout without it.
just let me know if im right

1) "cout" and "cin" are used with "<iosteam>",
2) "printf" is used with "<stdio>".

am i right ?

and last P.S.: i see that some tutorials use <iostream> and others use <iostream.h>;
some tutorials use <math>, others use <math.h>. Im a little confunse. Does the ".h" change something ? or is just the syntax of another version of C++ ?
Last edited on
Yes.
EDIT:
and last P.S.: i see that some tutorials use <iostream> and others use <iostream.h>;

Don't use <iostream.h>, always use <iostream> instead. iostream.h is an old header and not part of C++ standard.

some tutorials use <math>, others use <math.h>.

there's no difference between <cmath> and <math.h> except that <cmath> functions are under std namespace.
Last edited on
thanks again. really apreciated.
Topic archived. No new replies allowed.