what have i done wrong?

Soldato
Joined
9 Dec 2006
Posts
9,289
Location
@ManCave
im learning how to use functions (this is c)

my code
Error: 'Menu' : function does not take 0 arguments

im not sure what i have done wrong?i tried using void and failed worse?
Code:
[FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]
[FONT=Consolas][COLOR=#0000ff]#include[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"stdafx.h"[/COLOR][/FONT]
[/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]#include[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]<stdio.h>[/COLOR][/FONT]
[/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]#include[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]<stdio.h>[/COLOR][/FONT]
[/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#008000][FONT=Consolas][COLOR=#008000][FONT=Consolas][COLOR=#008000]//Function Prototypes[/COLOR][/FONT]
[/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] Menu ([/FONT][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] input);[/FONT]
[/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] _tmain([/FONT][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] argc, _TCHAR* argv[])[/FONT]
[FONT=Consolas]{[/FONT]
[FONT=Consolas]Menu();[/FONT]
[/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]return[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] 0;[/FONT]
[FONT=Consolas]}[/FONT]
[/FONT][FONT=Consolas][COLOR=#008000][FONT=Consolas][COLOR=#008000][FONT=Consolas][COLOR=#008000]//functions[/COLOR][/FONT]
[/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] Menu ([/FONT][/FONT][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff][FONT=Consolas][COLOR=#0000ff]int[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas] input)[/FONT]
[FONT=Consolas]{[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"===========================================\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"AppGecko Random Maths V0.30\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"===========================================\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"1. Addition\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"2. Subtraction - Not Complete\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"3. Division - Not Complete\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]printf([/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"4. Multiplication - Not Complete\n"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas]);[/FONT]
[FONT=Consolas]scanf( [/FONT][/FONT][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515][FONT=Consolas][COLOR=#a31515]"%d"[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Consolas][FONT=Consolas], &input );[/FONT]
[FONT=Consolas]}[/FONT]
[FONT=Consolas] [/FONT]
[/FONT]
 
The error message is telling you. You're running Menu() but you aren't passing a value of type int as the argument. If you run it with Menu(6) or Menu(argv[0])* then it will work.

* I think. argv[] holds all your command-line arguments, right? Obviously, you must pass an argument for it to work if you do that.

Edit: Are you wanting this to always show the menu before a user selects an option, or do you want them to be able to go straight to that option when launching the program?
 

What he said, the argument is something passed to menu so you'd have to give it an integer to work on.

It looks like you're trying to get a menu to come up, the user inputs a value and then the program reacts accordingly. In that case you should pass nothing to the menu function, but return an integer from it.

i.e. the prototype should be:

int menu();

(or int menu(void); if you like)

Then you create a new integer at the top of the the menu function

int input;

scanf will read from the standard input stream (i.e. keyboard) and put the number into your integer. Then you just need to return the input integer at the end with the command:

return input;

EDIT: You need this return command otherwise the compiler should complain at you telling you that menu doesnt return a value
 
Last edited:
Back
Top Bottom