Sorry to bother you all again... I keep on forgetting everything-and sometimes I just can't understand and keep on getting confused!
How do I call a function that has a ret type and takes an argument of ints? Let's call the ints x, and y. Please just give me an example...
How do I pass a value (like ints or floats) to a function? How does it work? Can someone give me an example?
And now for my damned homework. Need to create a program that takes two values, multiplies them, then takes the product and asks you to put in another number to multiply your product with, until you tell it to stop. Here's my attempt so far... I have my idea of how to do it but my functions and all that is a mess... I also put in some unfinished gotos so don't bother with those... but how can I implement my function where I want to?
Code:
float calc(float);
void main()
{
float x, y, z, prod1, prod2, prod_main, res;
int optn1, input;
printf("Please enter two values here");
scanf("%f %f", &x &y);
prod1=x*y;
printf("\nYour product is %f . If you would like to continue, press "1" key on your keyboard.", prod1);
printf("\nIf you want to stop, press the "2" key on your keyboard.");
scanf(" %d ", &input);
switch(input)
{
case 1: calc();
break;
case 2: //goto(end of program)
default: printf("\nInvalid Choice! Please pick either 1 or 2!");
}
printf("Please enter a number to multiply your sum with");
scanf(" %f ", &z);
//call program, PASS z and prod1 to function, function returns prod_main
calc(z, prod1);
//call program, get prod_main from function
prod_main=res;
printf("Your product is %f .If you would like to continue, press "1" key on your keyboard.", res);
printf("\nIf you want to stop, press the "2" key on your keyboard.");
prod1=ret_val;
goto(the printf that tells you your product);
//specify this place for the switch-case goto
getch();
}
//Let's declare our program
float calc(float cvar1, cvar2);
{
float ret_val;
ret_val=cvar1*cvar2
return(ret_val);
}
I haven't tried to compile it yet-and I also wanted to know: If the float I defined as ret_val is in the function, will it only work in the function program? Not in my main program? Please help... I'm confused to hell on this one and I can't take it nomore.