I wonder what's the final values of the variables "a, b and c" after this program... It is in pseudocode....

``````start
a = 2
b = 4
c = 10

while c > 6
perform changeBandC()
endwhile

if a = 2 then
perform changeA()
endif

if c = 10 then
perform changeA()
else
perform changeBandC()
endif

print a, b, c

stop

changeBandC()
b = b + 1
c = c - 1
return

changeA()
a = a + 1;
b = b - 1;
return``````

I tried to code to it...But nothing is printed...
I'll post it to ask you people what's wrong with my codes?

Here's my program...

``````#include <stdio.h>

int changeBandC(int,int);
int changeA(int,int);

int main()
{
int a = 2;
int b = 4;
int c = 10;

while (c > 6)
{
changeBandC(b,c);
}
if (a == 2)
changeA(a,b);
if (c == 10)
changeA(a,b);
else
changeBandC(b,c);

printf("%d,%d,%d",a,b,c);

getchar();
getchar();

}

int changeBandC(int b,int c)
{
int changeBandC = 0;
b = b + 1;
c = c - 1;

return changeBandC;
}
int changeA(int a,int b)
{
int changeA = 0;
a = a + 1;
b = b - 1;

return changeA;
}``````

I hope you could help me with this...

2
Contributors
1
2
Views
9 Years
Discussion Span
Last Post by Aia

Passing values on a function is done by making a copy of it, which means the original is not modified.

``````int changeBandC(int b,int c)
{
int changeBandC = 0; /* This is wrong here delete it */
b = b + 1; /*the work is done in b which  is a copy of the original b on main */
c = c - 1; /* c is a copy of the original c in main */

return changeBandC; /* it has not purpose here, it can only return one value and I ask you which value you think is returning? */
}``````

Here's how you change the value of an original variable in main

``````#include <stdio.h>

int change(int source);

int main(void)
{
int changeling = 1; /* lets give it a value that we know */

/* Notice the way the value produced by the function is returned */
changeling = change(changeling);

/* What's in variable changeling now? */
printf("Variable hold: \"%d\"\n", changeling);
return 0;
}

int change(int source)
{
source = source + 1;
return source;
}``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.