-4

I have done a simple program testing pointers, references, and recursion.

Here is the code to overlook (the problem is complained to come from PassAddresses' function):

#include <iostream>
using namespace std;
long RecRecur(short &caps);
void PassAddresses(short &address, short &address2, const char *nosey);
int main(int args, char **LOC)
{
short test = 15;
const char rosey = 0;
short myLick = 500;
short PersonalWhim = 250;
const char *LOG = &rosey;
RecRecur(test);
PassAddresses(myLick, PersonalWhim, LOG);
}
void PassAddresses(short &address, short &address2, const char *nosey)
{
address = address + address;
address2 += address;
for(short i = 100; i < 1000; i++)
{
for(short c = 50; c != 120; c++)
{
cout << "These are just for-loop tests...." << /n;
}
}
cout << address << /n << address2 << /n << nosey << /n << &rosey;
}
long RecRecur(short &caps)
{
caps--;
if(caps > 0x7CDE)
{
RecRecur();
}
else return;
}

Basically the compiler is complaining that a "primary-expression" is expected before the "/" character, and I am clueless on what the issue could be. The expressions/operators on the "address" value are perfectly interchangeable.

Jamal
  • 763
  • 7
  • 22
  • 32
  • 1
    What's the `/n` in that line supposed to mean? –  Nov 02 '13 at 21:39
  • A newline, what else? – Always Errors Nov 02 '13 at 21:39
  • http://stackoverflow.com/questions/8311058/n-or-n-or-stdendl-to-stdcout – Always Errors Nov 02 '13 at 21:40
  • The issue thrown is not towards the "/n", but before it. – Always Errors Nov 02 '13 at 21:41
  • 2
    A newline character is spelled `'\n'`, as you can also see in the question you've linked to. Please make sure you got basic syntax issues like this right before being conscending. –  Nov 02 '13 at 21:43
  • Right, the compiler has no idea what you're trying to divide by n. – David Schwartz Nov 02 '13 at 21:44
  • I changed it to that in my IDE, compiled, and get the following error: control reaches end of non-void function. Check my updated code above now, fixed. – Always Errors Nov 02 '13 at 21:46
  • 1
    Please don't make changes to the original code based on answers. That will invalidate them. – Jamal Nov 02 '13 at 21:50
  • 1
    where is your return value in your `int main()`? – UnholySheep Nov 02 '13 at 21:50
  • @UnholySheep: There is none, but I assume the `else return` is for another function. It's hard to tell with the lack of indentation. – Jamal Nov 02 '13 at 21:58
  • @Jamal: after counting the brackets, I find that the `else return`is for his `RecRecur()` function, but that cannot be correct? If it does actually work then it is still very bad style. But his second issue was probably caused by the lack of return in the `main()` – UnholySheep Nov 02 '13 at 22:01
  • @UnholySheep: Yep, not right. `RecRecur()` returns a `long`; it's not `void`. The explicit return in `main()` is not really needed in C++, but it doesn't hurt to have it anyway. – Jamal Nov 02 '13 at 22:05

3 Answers3

3

1. The escape character is '\', not '/'.

cout << address << /n << address2 << /n << nosey << /n << &rosey;

change above line with

cout << address << "\n" << address2 << "\n" << nosey << "\n" << &nosey;

or

cout << address << endl << address2 << endl << nosey << endl << &nosey;

2. Notice that you have a type in the same line. You may want to write nosey not rosey :)

3. RecRecur(); takes an argument please give one.

4. RecRecur() has to return a long

Vishnu Kanwar
  • 761
  • 5
  • 22
2

The escape character '\', not '/'. It also needs to be inside quotes:

cout << "hello world" << '\n';
Carl
  • 993
  • 8
  • 14
0

It's a simple syntax error - a newline is endl, not \n.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • Read this: http://stackoverflow.com/questions/8311058/n-or-n-or-stdendl-to-stdcout – Always Errors Nov 02 '13 at 21:40
  • 2
    I don't think suggesting that someone who can't debug an obvious syntax error needs to make decisions about when to flush standard output and when not to is a good idea. Keep it simple. When you understand the basics, then worry about details. – David Schwartz Nov 02 '13 at 21:42
  • Yes, but it forces you to decide when to flush and when not to. There's no reason to make things more complicated. – David Schwartz Nov 02 '13 at 21:45
  • @user2948710 Yeah, `"/n"` works. It's the string containing a slash character and the lower case letter n. I doubt that's what you wanted. `/n` without quotes, however, is simply a syntax error. Feel free to get a copy of the standard and check the grammar. –  Nov 02 '13 at 21:46
  • I understand that, but I fixed it and there's still issues. Look above, I updated everything. – Always Errors Nov 02 '13 at 21:49