i dont know how to pass variable values from a function to another..
i get this error passing arg 1of 'add' makes integer from pointer without a cast

here is my complete code:
(this is not complete as i am just starting a text-only calculator :P)

#include <stdio.h>

void main(void)
{
int iInput;
char ops;

printf ("First number:\n");
scanf ("%i", &iInput);
op(&iInput);
}

int op(int a)
{
int choice;
printf ("%i\n",a);
printf ("What operation?\n1 for addition\n2 for subtraction\n3 for multiplication\n4 for division\n");
scanf ("%i", &choice);
if (choice == 1)
{
	printf ("%i\n",a);
	add(&a);
}
else
	if (choice == 2)
{

}
else
	if (choice == 3)
{

}
else
	if (choice == 4)
{

}
}

int add(int a)
{
printf ("%i",a);

}

int sub()
{

}

int mul()
{

}

int div()
{

}

Remember that you are passing the 'address' of ilnput to op. If you have a look at the declaration of op you will see that it expects an 'int'. This means that a's value is the address of ilnput.

Also a case for the tests on 'choice' might be a better way to go.

Rather use

op(int *a)

thanks.. that solved it.. but cant i use some other variable?

Remember that you are passing the 'address' of ilnput to op. If you have a look at the declaration of op you will see that it expects an 'int'. This means that a's value is the address of ilnput.

Also a case for the tests on 'choice' might be a better way to go.

how do i code for switch-case? i am not sure how to do it in C.. is it the same in Java?

i am not sure how to do it in C

Look up in your book.

is it the same in Java?

There are minor differences between the break statements used inside switch-case in C and Java. Otherwise, it is similiar.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.