Value is incorrect??

This is a discussion on Value is incorrect?? within the C Programming forums, part of the General Programming Boards category; I am very new to this.. Tried to do some tutorials. Here's what i did.. No errors found on the ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    Question Value is incorrect??

    I am very new to this.. Tried to do some tutorials. Here's what i did.. No errors found on the coding but errors on the values. Can anyone tell me what did i missed?

    Code:
    #include <stdio.h>
    #include <conio.h>
    int main ()
    {
    	clrscr ();
    	printf ("House Price: 250000");
    
    	int a,b,c,d;
    	a = 250000.0;
    	b = .05;
    	c = a * b;
    	d = a - c;
    	printf ("\nBumiputra Price: %d",&d);
    
    	int e,f,g,h;
    	e = 250000.0;
    	f = .10;
    	g = e * f;
    	h = e - g;
    	printf ("\nDown Payment: %d",&g);
    
    	printf ("\n");
    	printf ("\nTotal House Price");
    
    	int i,j;
    	i = d - g;
    	printf ("\nBumiputra:%d",&i);
    	j = a - g;
    	printf ("\nNon-Bumiputra:%d",&j);
    
    	printf ("\n");
    	printf ("\nMonthly Instalment (20 years)");
    
    	int k,l,m;
    	k = 240;
    	l = i / k;
    	printf ("\nBumiputra: %d",&l);
    	m = j / k;
    	printf ("\nNon-Bumiputra:%d",&m);
    
    	getch ();
    	return 0;
    }
    same problem here.. =|

    Code:
    #include <stdio.h>
    #include <conio.h>
    main ()
    {
    	clrscr ();
    	int a,b,c,d,e,f,g,h,i,j,k,l;
    	printf ("Key in your Basic Salary:",&a);
    	scanf ("%d",&a);
    	b = 0.11;
    	c = a * b;
    	printf ("\nEPF:%d",&c);
    	d = 0.05;
    	e = a * d;
    	printf ("\nSOCSO:%d",&d);
    
    	printf ("\n");
    	printf ("\nKey in your overtime:",&e);
    	scanf ("%d",&e);
    	f = 6;
    	g = e * f;
    	printf ("Overtime payment:%d",&g);
    	printf ("\nKey in your travel distance:",&h);
    	scanf ("%d",&h);
    	i = 0.5;
    	j = h * i;
    	printf ("Travel allowance:%d",&j);
    	printf ("\nMedical claim (Type 0 if none):",&k);
    	scanf ("%d",&k);
    	l = a + g + j + k - c - d;
    	printf ("\nTotal salary:%d",&l);
    
    	getch ();
    	return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Integers cannot have fractional values... they are whole numbers only.

    int a = 10 ... valid
    int a = 0.5 ... invalid

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    2
    Thank you. =)

    Quote Originally Posted by CommonTater View Post
    Integers cannot have fractional values... they are whole numbers only.

    int a = 10 ... valid
    int a = 0.5 ... invalid

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Code:
    printf ("\nBumiputra Price: %d",&d);
    ...
    printf ("\nDown Payment: %d",&g);
    ...
    printf ("\nBumiputra:%d",&i);
    ...
    printf ("\nNon-Bumiputra:%d",&j);
    ...
    printf ("\nBumiputra: %d",&l);
    ...
    printf ("\nNon-Bumiputra:%d",&m);
    Code:
    printf ("Key in your Basic Salary:",&a);
    ...
    printf ("\nEPF:%d",&c);
    ...
    printf ("\nSOCSO:%d",&d);
    
    printf ("\n");
    printf ("\nKey in your overtime:",&e);
    ...
    printf ("Overtime payment:%d",&g);
    printf ("\nKey in your travel distance:",&h);
    ...
    printf ("Travel allowance:%d",&j);
    printf ("\nMedical claim (Type 0 if none):",&k);
    ...
    printf ("\nTotal salary:%d",&l);
    All those printf statements have problems falling into two categories.

    #1 When you print a variable's value, you do not use the address-of operator & (unless you are by chance actually attempting to print the address of the variable and not the value stored within). The "&" is only needed for your scanf statements.

    #2 The other problem is that some of your printf statements have additional arguments that aren't needed (there are no format specifiers in several of those printf calls and yet for some reason you seem to think you need to include the extra argument).
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash Table outputting incorrect number
    By Paul Skinner in forum C Programming
    Replies: 4
    Last Post: 11-20-2008, 05:19 AM
  2. incorrect initialisation
    By s_siouris in forum C Programming
    Replies: 2
    Last Post: 09-13-2006, 07:26 AM
  3. It is not incorrect to use void main
    By momo20016 in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 12-22-2002, 09:17 AM
  4. Replies: 3
    Last Post: 07-24-2002, 08:46 AM
  5. 'The parameter is incorrect' - LoadImage
    By DarkAvenger in forum Windows Programming
    Replies: 1
    Last Post: 04-12-2002, 02:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21