Question about my function

Hey all,

I don't see my fault.


I wish that in code below:
The result are the numbers from 1 up to the give 'n'.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//hs 5_4_som 1 - n
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void Optellen ();

int main()
{
	Optellen(); 
}

void Optellen ()
{
int n;
cout << "give number n: "; cin >> n;
cin.get();
cout << "the sum of 1 - n is: " << endl;

for (int x = 1; x <= n; x++)
{
cout << setw(3) << x;
}

}
Last edited on
To call a function you need to put parentheses after the function name.
thanks peter, have changed te code a bit, but still not working.
Yes, I can see you have changed it quite a bit.

When asking for help it is always useful to mention what it is that is not working. Is it a compilation error? A runtime error?

The code seems to compile so I'm just going to assume it is not giving you the output that you want. There are at least two problems that I can see.

1. In each iteration of the loop you add 1 but I think you instead want to add x.

2. When you print the getal variable at the end of the function you should not put quotation marks around it.
Now, changed it a little bit more..
And my code is running as i want.
Thank you!!
Topic archived. No new replies allowed.