Too Few Arguments To Function

Pages: 12
Error: too few arguments to function 'int FunctionA(float, float)'

I can't seem to fix this, I'm not really sure what to do. I'm still in the process of learning how to use functions and I'd deeply appreciate help.

I'm basically trying to make a calculator, convert a char to an int that works like an int defined by cin and it goes through the functions with two floats to find a result and return to the FunctionA where it started and print the answer.

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
	char Operator[] = "";
	int newOperator = 0;
	int Result = 0;
	float NumberA;
	float NumberB;

int FunctionC(){
	Result = NumberA - NumberB;
}

int FunctionB(){
	Result = NumberA + NumberB;
}

int FunctionA(float NumberA,float NumberB){
	system("cls");
	cout << "First Number:";
	cin >> NumberA;
	cout << "Second Number:";
	cin >> NumberB;
	
	if (newOperator == 1){
		FunctionB();
	};
	
	if (newOperator == 2){
		FunctionC();
	};
}

main(){

	cout << "Choose a Multiplication.\n" "Add\n" "Subtract\n";
	gets(Operator);
	
	if (Operator == "Add"){
		newOperator = atoi(Operator);
		newOperator = 1;
	};
	
	if (Operator == "Subtract"){
		newOperator = atoi(Operator);
		newOperator = 2;
	};
	
FunctionA();
cout << Result;

	return 0;
}
Last edited on
closed account (Dy7SLyTq)
a) int main not main
b) your calling functionA at line 51 with no arguments
This statement

gets(Operator);

leads to undefined behaviour because Operator was defined as an array of only one element. Moreover this statement

if (Operator == "Add"){

compares addresses of Operator and string literal "Add". As they have different addresses the expression will be always equal to false though Operator does not contain string "Add".
Last edited on
closed account (zb0S216C)
vlad from moscow wrote:
"As they have different addresses the expression will be always equal to true false"

Not necessarily. With optimisations enabled, a smart compiler will place all identical strings into one location within static memory to save space. If the latter is true, then comparing two strings may always yield true, not false. Though, this may be beyond the scope of the OP's question, but it's relevant.

Wazzak
Last edited on

@Framework

With optimisations enabled, a smart compiler will place all identical strings into one location within static memory to save space. If the latter is true, then comparing two strings may always yield true, not false. Though, this may be beyond the scope of the OP's question, but it's relevant.



There is no a comparison of two string literals. There is a comparison of the address of Operator and some string literal.
> if (Operator == "Add"){
> compares addresses of Operator and string literal "Add".
> As they have different addresses the expression will be always equal to false

It results in unspecified behaviour.

Tip: compile your code with all warnings enabled.

1
2
const char Operator[] = "Add" ;
Operator == "Add" ; // warning: comparison with string literal results in unspecified behaviour 
@JLBorges
It results in unspecified behaviour


No, the result is very well specified and will be equal to false because there is a comparison of the address of the first element of array Operator with the address of the first element of other array that has no name and contains string literal "Add".
Last edited on
> No, the result is very well specified.

That the earth is flat is very well specified. By the the Flat Earth Society.
I trust you that their specifications are well done because personally I do not know this Society.
@JLBorges


Maybe you are right because these two pointers do not belong to one array. But I am lazy to read the standard.:)
@JLBorges


I read the standard and it is me who is right not you.

From the C++ Standard

Pointers of the same type (after pointer conversions) can be compared for equality. Two pointers of the same type compare equal if and only if they are both null, both point to the same function, or both represent the same address
Last edited on
> I read the standard and it is me who is right

Great. So you should continue to believe that the result of a pointer comparison with a string literal is not unspecified.
Yes the result is well-defined. As it follows from the quote the result will be always equalt to false because the both expressions (operands) do not represent the same address.
closed account (Dy7SLyTq)
its not comparing addesses vlad its comparing a "pointer to a memory location" to a string literal, not its memory location

edit: put quotes around pointer..location to show its one thing. other wise it looks like i mean comparing a pointer, a memory location, and a string liiteral
Last edited on
@DTSCode

its not comparing addesses vlad its comparing a pointer to a memory location to a string literal, not its memory location


String literals in C++ have type const char [] that is they are arrays. In expressions the same way as other arrays they are converted implicitly to the pointer to the first element

Otherwise if to follow your logic the following code has no sense

const char *p = "Literal";

What is assigned to p?:)

const char *q = Operator;

And what is assigned to q?

Compare these two expressions.
Last edited on
> its not comparing addresses

It is comparing addresses alright; it is just that the result of the comparison with a string literal is unspecified. This thread goes on and on because vlad from moscow is ignorant about the differences between undefined behaviour, implementation defined behaviour and unspecified behaviour. And he is ignorant about his ignorance.

I'm getting out of here.
closed account (Dy7SLyTq)
could you show me where in the standard it says that? im not arguing im just curious?
You are mistaken. I see the difference between undefined behaviour and unspecified behaviour. The standard specified very well the result of the comparision of two pointers of the same type. Read one more the quote I posted.
@DTSCode

could you show me where in the standard it says that?


says what?
closed account (Dy7SLyTq)
sorry should have been clear *facepalm*.
String literals in C++ have type const char [] that is they are arrays. In expressions the same way as other arrays they are converted implicitly to the pointer to the first element

^that. and also i understand what you wrote below that, but that wasnt i was saying. i get comparing pointers, but i didnt think string literals were converted to char *'s so in my mind it was comparing two different data types, like testing float myfloat(1.4) == bool mybool(false)
Pages: 12