ok so I have another question now on returning numbers.
I have gotten this little program to run as I'd like it to but now I'm trying to do more with the code. basically I'm trying to make everything run as a function so all I do is call functions.
originally input() was part of main(). not only that but the printf() lines at the end of mult() and div() were incorporated in main() as well. Everything was fine until I tried to take the content that is in input() out of main(). the first section of code works perfectly. the second section is what I'm trying to make work in the same way. Can someone explain to me where my mistake is?
Thanks a million
Code:
/*
Learning the ropes
This Works!!!!
*/
#include <stdio.h>
int x,y;
float z,r;
int mult(int x,int y);
float div(int x,int y);
int main()
{
printf("\nPlease enter a number: ");
scanf("%d",&x);
printf("\nPlease enter a second number: ");
scanf("%d",&y);
mult(x,y);
printf("\nand");
div(x,y);
printf("\nHave a nice Day!!!\n");
return 0;
}
int mult(int x,int y)
{
z=x*y;
printf("\n%d times %d equals %.2f",x,y,z);
return 0;
}
float div(int x,int y)
{
z=x/y;
r=x%y;
r=r/y;
z=z+r;
printf("\n%d divided by %d equals %.2f",x,y,z);
return 0;
}
Code:
/*
Learning the ropes
got it to work now trying to add functions instead of just
*/
#include <stdio.h>
int x,y;
float z,r;
int mult(int x,int y);
float div(int x,int y);
float input(int x, int y);
int main()
{
input(x,y);
mult(x,y);
printf("\nand");
div(x,y);
printf("\nHave a nice Day!!!\n");
return 0;
}
float input(int x, int y)
{
printf("\nPlease enter a number: ");
scanf("%d",&x);
printf("\nPlease enter a second number: ");
scanf("%d",&y);
return x,y;
}
int mult(int x,int y)
{
z=x*y;
printf("\n%d times %d equals %.2f",x,y,z);
return 0;
}
float div(int x,int y)
{
z=x/y;
r=x%y;
r=r/y;
z=z+r;
printf("\n%d divided by %d equals %.2f",x,y,z);
return 0;
}