simple c question

This is a discussion on simple c question within the C Programming forums, part of the General Programming Boards category; some of you may have looked at my earlier post, basically, i'm making a ecosystem simulation based on the following ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    12

    simple c question

    some of you may have looked at my earlier post, basically, i'm making a ecosystem simulation based on the following mathematical model -

    (a/b*c) -(d/e*c)+(a/b*c)

    there is a ? out of ? chance that an animal will be created, and a ? out of ? chance that something will be destroyed. the math model basically just shows the final amount of animals.

    so far what i've got -

    Code:
    #include <stdio.h>
    main()
    {
          
          float a,b,c,d,e,f,g,h,i;
          printf("number of seconds");  
          scanf ("%d",&c);
          printf("first number for creation");
          scanf("%d",&a);
          printf("second number of creation");
          scanf("%d",&b);
          printf("first number of destruction");
          scanf("%d",&d);
          printf("second number of desturction");
          scanf("%d",&e);
          f=(a/b*c) -(d/e*c) +(a/b*c);
          
          
          printf("the final amount is %d\n",f);
    }
    i've tried so many different things...and yet nothing works...
    help!!!

    thanks in advance,

    JOlszewski

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    use %f instead of %d

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    13
    Thats what I was about to say. Your identifiers are set up as floating point numbers :

    Code:
    float a,b,c,d,e,f;
    Yet when you call them in your code, you are accessing them as integers:

    Code:
    scanf("%d", &a);
    Your basicaly confusing the program.

    Code:
    #include <stdio.h>
    
    main()
    {
          float a,b,c,d,e,f;
          printf("number of seconds\t");  
          scanf_s("%f",&c);
          printf("first number for creation\t");
          scanf_s("%f",&a);
          printf("second number of creation\t");
          scanf_s("%f",&b);
          printf("first number of destruction\t");
          scanf_s("%f",&d);
          printf("second number of desturction\t");
          scanf_s("%f",&e);
          f=(a/b*c)-(d/e*c)+(a/b*c);
    	        
          printf("the final amount is %f\n",f);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

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