# Urgent helpppp!!

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 09-19-2012
qny
Quote:

Originally Posted by Noor
Why wont this work?

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; }```
• 09-19-2012
Noor
Code:

```#include <stdio.h> int main(void) { int digit1,digit2,digit3,digit4; printf("Enter an encrypted 4-digit combination:"); scanf("%d%d%d%d",&digit1,digit2,&digit3,&digit4); digit1=digit1+digit4; digit2=9-digit2; digit3=9-digit3; digit4=digit1-digit4; digit1=digit1-digit4; printf("The real combination is:%d",digit1,digit2,digit3,digit4); return 0; }```
i put in 8021 and thsi is what i got:
The real combination is:11735520
• 09-19-2012
WaltP
You have been told TWICE what you are doing wrong! Repeating here:
Quote:

Originally Posted by Salem
you will need to type in
1 2 3 4
rather than
1234

Quote:

Originally Posted by Salem
Next, you need to type in say
1 2 3 4
as opposed to say
1234

That is, you need a space between each digit.

Now, if you still can't do it correctly, you might have to talk to your instructor.
• 09-19-2012
Break it down, to debug it:

1) Are you getting the digits into the variables, correctly? Use a printf("%d %d %d %d\n",digit1,digit2,digit3,digit4); getchar(); getchar(); (two of them here), line of code, right after the input is finished, to see how it looks.

2) Check your equations. What should they be? If you should have only 4 digits, then any digit over 9 is (almost surely), wrong.
• 09-19-2012
Click_here
Quote:

Originally Posted by Noor
Why wont this work?
Code:

```#include <stdio.h> int main(void) { int digit1,digit1,digit3,digit4; printf("Enter an encrypted 4-digit combination:"); scanf("%d%d%d%d \n",&digit1,&digit2,&digit3,&digit4); digit1=digit1+digit4; digit2=9-digit2; digit3=9-digit3; digit4=digit1-digit4; digit1=digit1-digit4; printf("The real combination is:"); scanf("%d%d%d%d",digit1,digit2,digit3,digit4); return 0; }```

1) Your first scanf has not changed. See my earlier post on how to do that :)

2) You are using scanf at the end of this when you should be using printf.
Code:

```printf("The real combination is:"); scanf("%d%d%d%d",digit1,digit2,digit3,digit4);```
The only things wrong with your original code were: Line 6 - remove the space and '\n' character as I suggested in post 10 - Remove the '&' in front of the variable names in the last printf as I suggested in post 11.

If you go back to the original code and change these two things, your code will run.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12