# Thread: C noob with some issues

1. ## C noob with some issues

So I'm on university doing 3th grade of computer sciende (a 4 year career) but I have no idea on how to code so it was actually quite hard for to me to pass this semester (who would have thougth!?).
Becouse of this I decided to start learning C again, I did learn to code in pseudocode and C in first year but forgot how to.
Today I was trying to make an algorithm that would return all the A, B, and C variables (all between 0 and 9) such that (10A+B)/(10B+C)=A/C becouse the solutions are nice and I had already solved the equation by hand and already knew all the solutions. But I just can't make it work, I'm using an online C compiler and it doesn't show any error so I guess it's stuck in a loop.
This is my sloppy code;

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

int
main ()
{
int a, b, c, d, e;
while (a + b + c != 27)
a = 0;
b = 0;
c = 0;
a = a++;
if (a = 9)
a = 0;
b = b + 1;
if (b = 9)
c = c++;
d = (10 * a + b) / (10 * b + c);
e = a/c;
if(d=e)
printf ("%d",a);
printf ("%d",b);
printf ("%d",c);
return 0;
}```

Thanks!

2. I think it never gets out of the loop becouse C keeps getting bigger, I have this now:

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

int
main ()
{
int a, b, c, d, e;
while (a + b + c != 27)
a = 0;
b = 0;
c = 0;
a = a++;
if (a = 9)
a = 0;
b = b++;
if (b = 9)
b=0;
while(c<=9)
c = c++;
d = (10 * a + b) / (10 * b + c);
e = a/c;
if(d=e)
printf ("%d",a);
printf ("%d",b);
printf ("%d",c);
if(c=9)
a=30;
return 0;
}```

3. I think your problem is a lack of change in the variables, all your while loop is doing is setting a to 0, also variables must be initialized BEFORE trying to use them, your loop starts with a, b and c equaling some random number left over from previous usage, in this case it's probably 0 although there's no garuntee on that, so 9999 times out of 10000 a + b + c will never equal 27 which means your loop never ends which means the app never progresses to b = 0;

4. Are you aware that C isn't Python, don't ya?

5. C uses curly brackets to indicate blocks. YOu need to read some C code to get the idea of the syntax.

6. Guys, I was trying to be subtle about it, you both just handed the answer on a silver plate to xem

7. Originally Posted by awsdert
Guys, I was trying to be subtle about it, you both just handed the answer on a silver plate to xem
You make a good point, but our homework policy mainly forbids people asking for others to do their homework for them, and consequently we discourage contributors from doing people's homework for them too. Hence, there's a fair bit of leeway in helping as long as we aren't handing out code that can be used as-is or other answers that don't require the help seeker to adapt/apply the help given for themselves. Both flp1969's reply and Malcolm McLean's reply thus fall within this acceptable range of answers: they're just somewhat more obvious hints than yours (and maybe not for flp1969's case: it assumes Ptolemaic knows Python, but the poor indentation means that a Python version of Ptolemaic's code wouldn't even be syntactically correct).

8. Originally Posted by laserlight
You make a good point, but our homework policy mainly forbids people asking for others to do their homework for them, and consequently we discourage contributors from doing people's homework for them too. Hence, there's a fair bit of leeway in helping as long as we aren't handing out code that can be used as-is or other answers that don't require the help seeker to adapt/apply the help given for themselves. Both flp1969's reply and Malcolm McLean's reply thus fall within this acceptable range of answers: they're just somewhat more obvious hints than yours (and maybe not for flp1969's case: it assumes Ptolemaic knows Python, but the poor indentation means that a Python version of Ptolemaic's code wouldn't even be syntactically correct).
*face palms* didn't even occur to me that it was xer homework, glad I took the route of a subtle answer

9. Originally Posted by awsdert
*face palms* didn't even occur to me that it was xer homework, glad I took the route of a subtle answer
It might not be formal homework, but besides the fact that we cannot be sure, there's also the thing where applying stuff rather than just using it as-is usually leads to better learning outcomes, whether the problem was set by some instructor or boss or the help seekers for themselves. So you're doing the right thing, but it isn't (necessarily) the case that flp1969 and Malcolm McLean are doing the wrong thing.

10. Guys this is not my homework lmao, we don't even have homework at my univeristy.
Nobody is gonna tell me how to fix it then?

11. I have this now but it doesn't return anything:
Code:
```int main()
{
int a, b, c, d, e;
a=0;
b=0;
c=0;
d=0;
e=0;
while(c!=9 && b!=9 && a!=9)
a=a++;
if(a=9)
a=0;
b=b+1;
if(b=9)
b=0;
c=c++;
d=(10*a+b)/(10*b+c);
e=a/c;
if(d=e)
printf("%d",a);
printf("%d",b);
printf("%d",c);
return 0;
}```

12. 1. You need lots of braces. C isn't Python. Just because you indented it nicely doesn't make C follow a different path through the code.

2. Use == in place of =, if you want to compare two values.

3. Don't mix = and ++ together with the same variable.

So at a minimum, you need something like
Code:
```    while(c!=9 && b!=9 && a!=9) {
a++;
if(a==9) {
a = 0;
}
}```

13. Many thanks!