Im 15 years old and just starting out with programming. I was wondering if anyone could help a begginer out with a simple code. Basicly im adding 2 integers together, 1 is already set and the other i get from the user. If the 2 integers are equal i want a certain message to dislplay, but for some reason when i use "if" it just displays the message regardless of the value. It also will not add. Here is the code.
[code]
#include <stdio.h>
#include <stdlib.h>
int one(int a, int b,int ans);
int a;
int b;
int ans;
char cnuma[20];
int main(int argc, char *argv[])
{
b=15;
printf("Hello, my age is %i years old, what is your age?\n", b);
gets(cnuma);
a=atoi(cnuma);
one(a,b,ans);
}
int one(int a, int b, int ans)
{
ans=a+b;
if(b=a)
{
printf("You say your age is %i? Hey we are the same age!!!\n",a);
printf("This gives us the combined age of %i\n", a);
system("pause");
return 0;
}
printf("You say your age is %i, this makes are combined ages %i.\n", a, ans);
system("pause");
return 0;
}
[code]
when i compile and run the program without the message it will state the age of the person and the combined ages like its sopposed to. when i compile it with the "if" in there it says the "if" message no matter what and instead of adding the 2 numbers it just repeats the second. Thanks for the help.