I am supposed to ask the user for a 3 digit number and then replaces each digit by that digit plus 6 modulus 10, then sum all update digits. When I run the program it crashes after I enter a number, warning:
format %d expects argument of type 'int *' but argument 2 has type int.
Here is my source code:
#include <stdio.h>
int main(int argc, char* argv[])
{
int Integer;
int Divider;
int Digit1, Digit2, Digit3;
printf("Enter a three-digit integer: ");
scanf("%d", Integer);
Divider = 1000;
Digit1 = Integer / Divider;
Integer = Integer % Divider;
Divider = 100;
Digit2 = Integer / Divider;
Integer = Integer % Divider;
Divider = 10;
Digit3 = Integer / Divider;
Digit1 = (Digit1 + 6) % 10;
Digit2 = (Digit2 + 6) % 10;
Digit3 = (Digit3 + 6) % 10;
printf(Digit3 + Digit1 + Digit2);
getch();
return 0;
}
Update
In our example output if the user enters 928 the resulting number should be 584. I'm not exactly sure how that number is made. It should replace each digit by the sum of that digit plus 6 modulus 10. So is there a math error in my code as well?
scanffor user input. Usefgetsinstead.main(), then use the signature:int main( void )scanf()requires the address of its' parameters, so it knows where to place the converted input. so this line:scanf("%d", Integer);should be:scanf("%d", &Integer);Also, always check the returned value to assure the operation was successful. I.E. `if( 1!=scanf( "%d", &Integer ) ) { perror( "scanf failed" ); exit( EXIT_FAILURE ); } Note: exit() and EXIT_FAILURE found in stdlib.hprintf()expects the first parameter to be aformat stringso suggest:printf( "%d %d %d", DIgit3, Digit1, Digit2 );