Function does not take 0 arguments

Hello, I'm very new to C++ programming and I'm trying to get this script to work and the only error that I'm getting is:

Function does not take 0 arguments


I've googled this error to attempt to learn from other programmers mistakes, but after looking at several examples I still can't seem to find out what's wrong with my coding. It would be greatly appreciated if someone could take a look at it and get back to me on what I did wrong:

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
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <iostream>

float problem2a(float x, float y)
{

	printf("Please enter two floating point values: ");
	scanf("%f %f", x, y);
	printf("The two floating point values you have entered are: ");
	printf("%f and ", x);
	printf("%f\n", y);

	printf("%f ", x); 
	printf("and %f", y);
	printf("are multiplied together the result is: %f", x * y);

	return x * y;

}

float main()
{
	problem2a();
}


I believe it has to do with the bolded/underlined section, but I'm not quite sure on how to fix this error. Any help is appreciated, thanks.
Last edited on
main() cannot be of type float. It's not legal, and you should change it to int. :(

I'd make problem2a not take any arguments (get rid of the underlined part) and just declare your variables inside the function normally: float x, y;

-Albatross
Excellent thank you for the quick response, I fixed that part and now my code looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
float problem2a()
{
	float x, y;
	float result = x * y;
	
	printf("Please enter two floating point values: ");
	scanf("%f %f", x, y);
	printf("The two floating point values you have entered are: ");
	printf("%f and ", x);
	printf("%f\n", y);

	printf("%f ", x); 
	printf("and %f", y);
	printf("are multiplied together the result is: %f", result);

	return result;

}

int main()
{
	problem2a();
}


Though when I run the program I get a run time error that says:

The variable "x" is being used without being initialized


I thought I initialized it when I put
float x;
in the function, but I guess I'm wrong >.<

Thanks again for the help.
Last edited on
You are trying to multiply x and y before you have given them any values. Try moving your multiply instruction after you have accepted values for x and y. You can't multiply something that you don't have...
Computer programs are not mathematical equations. They are lists of instructions to be obeyed in strict order. ;o)
Makes sense, anyways it works now:

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
float problem2a()
{
	float x;
	float y;
	
	printf("Please enter two floating point values: ");
	scanf("%f ", &x);
	scanf("%f ", &y);

	float result = x * y;

	printf("The two floating point values you have entered are: \n");
	printf("%f and ", x);
	printf("%f\n", y);

	printf("%f ", x); 
	printf("and %f", y);
	printf("are multiplied together the result is: %f", result);

	return result;

}

int main()
{
	problem2a();
}


Not only did I switch the placement of the x * y = result portion of the code, but I put & in front of x and y when it goes to scan. Works like a charm now, thanks a lot!

And yes, a very strict order as I'm learning xD
Last edited on
Topic archived. No new replies allowed.