Originally Posted by
Noor
Why wont this work?
Pay attentio to my comments inside your code
Code:
#include <stdio.h>
int main(void)
{
int digit1,digit1,digit3,digit4;
// ^^^^^^ repeat same variable?
printf("Enter an encrypted 4-digit combination:");
scanf("%d%d%d%d \n",&digit1,&digit2,&digit3,&digit4);
// ^^^ ^^^^^^
// what's with the whitespace?
// digit2 undefined
// let's suppose the digits were 4, 7, 0, and 3
digit1=digit1+digit4; // digit1 = 7 (4 + 3)
digit2=9-digit2; // digit2 = 2 (9 - 7)
digit3=9-digit3; // digit3 = 9 (9 - 0)
digit4=digit1-digit4; // digit4 = 4 (7 - 3)
digit1=digit1-digit4; // digit1 = 3 (7 - 4)
printf("The real combination is:");
scanf("%d%d%d%d",digit1,digit2,digit3,digit4); // 3294
// scanf??? don't you want to print the result now?
return 0;
}
Please improve your indentation. Thank you.