Hello!
I have to learn C++ as part of my programming class, so my question today is how to deal with a certain exercise.
I am a very beginner and I am aware of the fact that I make very basic mistakes, so please don't yell at me - I'm willing to learn.
oh, and by the way I'm not a native speaker, formulations might be a little off!
So, the exercise was to have a variable count upwards by one (up to 1000) and to have them in one line up to the number 8, then a new line the numbers from 8 to 16, a new line with the numbers from 16 to 24, and so on.
So what I did is, that I made the variable count upwards by one (x++) and then I tried to build an if-function that calculates if a division of x/8 has a remainder. And if not, so if r==0, i want a newline token to be inserted.
So the code I have now is the following:
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 27 28 29 30
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main ()
{
int x=1;
while (x<=10)
{
cout << x << '\t';
x++;
int division(int x)
{ int r;
r=x & 8;
if (r==0)
return cout << '\n' ;
}
}
return EXIT_SUCCESS;
}
|
note= as "up to 1000" was too much for me in the beginning and my compiler only showed the numbers back to 700 i reduced the number the variable should count up to to 10.
The compiler now states: In function 'int main()': error: a function-definition is not allowed here before '{' token
{ int r;
^
I dont really understands what that means and what the problem is.
Thank you very much for your help and advice in advance!