I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me.
For example this code
#include <stdio.h>
main()
{
unsigned long a=0;
unsigned long b=0;
int z;
{
printf("Enter two digits you want to add seperated by a space:");
scanf("%u %u", a, b);
}
z= a + b;
printf("\n%u\n", z);
}
Its because I forgot the &'s! Okay I got it nevermind
---------- Post updated at 11:39 AM ---------- Previous update was at 10:33 AM ----------
#include <stdio.h>
main()
{
unsigned long c=0;
unsigned long a=0;
unsigned long b=0;
unsigned long z;
unsigned long noBits = 32;
unsigned long x = (1 << noBits - 1);
unsigned long y = 129;
int i;
unsigned long k;
unsigned long t;
unsigned long g;
{
printf("Please choose a function\n Calc (1)\n Binary convertor (2)\n");
scanf("%u", &c);
{
if (c == 1)
{
{printf("\n 1 for addition\n 2 for subtraction\n 3 for multiplication\n 4 for division\n");
scanf("%u", &g);
printf("\nEnter two digits seperated by a space:");
scanf("%u %u", &a, &b);
if (g==1)
{z= a + b;
printf("\n%u\n", z);}
if (g==2)
{z=a - b;
printf("\n%u\n", z);}
if (g==3)
{(z= a * b);
printf("\n%u\n", z);}
if (g==4)
{(z= a / b);
printf("\n%u\n", z);}
printf("\n%u\n", z);
}
}
if (c == 2)
{printf("Enter any whole number:");
scanf("%d", &y);
for (i=noBits - 1; i >= 0; i--)
{
printf("i = %d ", i);
x = 1 << i;
k = x & y;
if (k != 0){
printf("binary = 1\n");
} else {
printf("binary = 0\n");
}
}
}
}
}
}
why doesnt the calculator work!