problem with running this code

Thread Starter

TAKYMOUNIR

Joined Jun 23, 2008
352
Rich (BB code):
Rich (BB code):
include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int x,y,w,z,f1,f2;
printf("enter four numbers");
scanf("%d%d%d%d",x,y,w,z);
f1=x-y-w-z;
f2=x-y-(w+z);
printf("numbers f1 is %d and f2 is %d",f1,f2);
return 0;
}
 

Attachments

Last edited:

kubeek

Joined Sep 20, 2005
5,795
You´ve been here a while, so you might have noticed we got here what is called code tag, which lets you post the code right here.
Rich (BB code):
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
   int x,y,w,z,f1,f2;
   printf("enter four numbers");
   scanf("%d%d%d%d",x,y,w,z);
   f1=x-y-w-z;
   f2=x-y-(w+z);
   printf("numbers f1 is %d and  f2 is %d",f1,f2);

    return 0;
}
Look here, see where you problem is? http://www.cplusplus.com/reference/clibrary/cstdio/scanf/
That should help you with the first one, the second is that you should have spaces between the %d in the scanf function, else it won't recognize the rest of the numbers.
 

panic mode

Joined Oct 10, 2011
2,736
in addition to comment by kubeek, your variables need & in front of each variable in SCANF instruction. this is one of the classic pitfalls of programming in c.
 

spinnaker

Joined Oct 29, 2009
7,830
Not to mention not giving proper error messages.

I doubt you would be getting the message "that the program stop working".

I think panic mode has it. Scanf needs a pointer to a variable not the variable itself. & get the address of the variable i.e. it's pointer.
 

Thread Starter

TAKYMOUNIR

Joined Jun 23, 2008
352
Rich (BB code):
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
   int x,y,w,z,f1,f2;
   printf("enter four numbers");
   scanf("%d%d%d%d",x,y,w,z);
   f1=x-y-w-z;
   f2=x-y-(w+z);
   printf("numbers f1 is %d and  f2 is %d",f1,f2);
    return 0;
}
 

John P

Joined Oct 14, 2008
2,026
You still need to make it
Rich (BB code):
   scanf("%d%d%d%d", &x, &y, &w, &z);
Personally I think spaces between the list elements makes it easier to read, but you don't have to.
 
Top