-3

This is a code that takes a series of 3 numbers in a number pattern and figures out the difference between them. everything seems to be right but my compiler keeps telling me I need an initializer before int i? sorry, I'm new to C++ so I'm sure my code is horrible.

using namespace std;

void add(int a, int b, int c)
    int i;
    for (a+i!=b;b+i!=c)
    {i=0; i<100; i++;}
    else {cout i;}
};
int main()
{
    int x, y, z;
    cin>>x;
    cin>>y;
    cin>>z;
    add(x, y, z);
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 3
    Look before `int i` and you'll find you're missing something. And I'm not sure what this has to do with design patterns. – chris Oct 14 '13 at 02:12
  • 2
    You're missing some bracing and you have an `else` without an `if`. Neither leads to happiness. The body of your `for` loop is odd, too; it looks a bit like the condition of a `for` loop…whereas your `for` loop control is missing at least one semicolon. You don't need a semicolon after a function definition. You do need a `#include ` too, I believe. – Jonathan Leffler Oct 14 '13 at 02:16
  • 4
    This question appears to be off-topic because it is about fixing basic syntax errors and will provide little or no help to future visitors to SO. – Jonathan Leffler Oct 14 '13 at 02:23
  • 2
    `cout i;` will only lead to tears, too. – Crowman Oct 14 '13 at 02:23
  • 1
    You have multiple syntax errors. Compile the code, look at the *first* reported syntax error, and fix it. The error message might be misleading; use it to indicate which line the error is on (it might be on the previous line to the one reported). Repeat the above until your code compiles cleanly. But note that code that compiles cleanly may still have bugs. – Keith Thompson Oct 14 '13 at 02:29
  • 1
    C++ doesn't have an `else` clause to `for` like Python does. Anyway, this code looks like you're typing random things and hoping the compiler will take it; I'm not sure *you* even know what the code is supposed to do. If you want anyone to help you, you need to describe *in English* what the code should do. – Mike DeSimone Oct 14 '13 at 02:38
  • [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Blastfurnace Oct 14 '13 at 02:54

1 Answers1

1

Many things, first you're missing a curly braze after your add function.

Also, you have one extra ; in your for declaration.

Also, after your function add there shouldn't be a ;

Pacane
  • 20,273
  • 18
  • 60
  • 97
  • `main` returns 0 when it hits the end, and that's a function *definition*. – chris Oct 14 '13 at 02:16
  • `main` isn't required to explicitly return an integer. – Mars Oct 14 '13 at 02:17
  • Removed it. But out of curiosity, I thought you had to make it void if you didn't make it return an int. – Pacane Oct 14 '13 at 02:33
  • @Pacane: `void main()` is just wrong. `main()` is the only function that will implicitly return a value if you don't explicitly do so. – Crowman Oct 14 '13 at 02:35
  • @PaulGriffiths I was looking at this though and it doesn't say that. You should add your answer! http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c – Pacane Oct 15 '13 at 23:08