Allow us to remind you that first_screen is a function, and must be called with arguments and a call operator (). You would probably also do well to remember the return in main, and convert that first semicolon on line 8 to a comma.
Then reindent the function and come back to us. (Seriously though, I don't think I can see anything wrong with the function, I'd just stop stacking multiple statments up onto one line.)
And "him"?
EDIT: OK, some quick review revealed another error on line 25. I'm sure you can figure it out. (It's when statements get clumped up like this that that happens.)
Line 14's error I addressed in my last post.
And you cannot switch on a function. A function is not a variable or expression; you cannot define a switch to go around it.
What are you trying to do anyway? That will help you determine what you should be doing in the function.
First things first as stated above you should try to place everything in separate lines so your code is easier to read. However you have 3 mistakes.
If you look at your code this line is incorrect:
char name[20]; password[6];
Reason:
You can not have the ; after a type declaration and have the next variable name be associated with that type variable. The line needs to be
Correction:
char name[20], password[6]; will work however much nicer to do this
char name[20];
char password[6];
Next minor problem is the fact you didn't close out your function after using the switch statement. You closed the switch statement but never closed the function therefore the compiler has no clue as to when the function first screen ends.
Your next error is both logic error and syntax error in your switch statement. Your switch statement reads switch(first_screen) which is ok if first_screen returned some type of simple variable type however first screen is a void function thus returns nothing. Depending on what your want your switch statement (which appears to want a char value).
Look at those and then ask again if you need more info on what your doing wrong.
@jshafferman, the function does have a complete set of curly brackets. The indenting is just really bad. And the switch would still be wrong if firstscreen had a return - firstly because the recursion would be infinite and secondly because you still need to provide a call operator and the required arguments.
tummy , if i understand u good , u say i fall to recursion ? how can i fix it?
where is my recursion ?
where should i put my return ?
what wrong with my switch statment?
@tummychow, whoops I forgot that the infinite recursion would occur in this situation and also the obvious need for the correct call to the function in general but I thought that was already stated earlier but anyhow, yes the correct call with correct arguments is needed for the function to be ran regardless of how you intend to program it.
@snoopy as tummychow stated you must call your function with the correct arguments in your case first_screen(int , int, int) as you have it right now.
You need a base case for recursion otherwise you will get infinite recursion. You would need some case statement to end the program, such as:
default:
return; // for a void function
The way you have it coded it will run forever because the function will just keep calling itself until the activation stack is filled up then your program will just fail at that point.
No, I'm saying there would be infinite recursion if you called your function in the switch. You probably shouldn't do that anyway. (unless you had good reason but I don't even know what you are trying to do.)
Line 17's error is a result of the semicolon at the end of line 16. When you define a function you do not end its argument list with a semicolon.
I'll be really clear for line 14. I don't want to sound like I'm babying anybody though something but... you asked. When you refer to a function, you must include the call operator thereafter:
1 2 3 4 5
void foo();
int main()
{
foo(); // The bold part is the call operator
}
Even if you have no arguments you must put the call operator there, otherwise you are not calling a function and will probably collide headfirst into an error.
If you have arguments you must include those as well:
1 2 3 4 5
void foo(int, char);
int main()
{
foo(3, 'c'); // The bold part is the call operator
}
So when you refer to firstscreen, since it is a function you must *call* it.
'{' missing function header (old-style normal list?)
Misplaced semicolon at the end of line 16.
Use either spaces or tabs for indentation, but not both. Otherwise, the structure gets screwed up when the size of tab changes (you're using tabs of size 4 and the website is using 8).
Code tags not output tags.
Not bad. If that's what the OP actually wanted then it should work fine.
(Although there's no reason for any of those variables to be global actually. The password and name are not referred to in main so they can be declared in the function, and choice can be declared in main and is passed, so no need for that to be global either. I personally avoid using globals if I can.)
(And lastly, you can and should probably replace those char[] with strings. More effective and reliable.)
Why would you write it for him??? Let him do it himself, but tell him how. That way he learns. What's the point of writing it for him? He doesn't learn anything that way!