Thread: Whats wrong with this?

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    10

    Whats wrong with this?

    Code:
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <math.h>
    
    // Variable List
    
    double side,area;
    int count;
    
    void main(void)
    
    {
    	clrscr();
       for(count=0;<=5;count=count++1)
       {
       printf("Enter area:\n");
       scanf("%;f",&area);
       if((area<=10)&&(area>=2))
       {
       	side=sqrt(area);
       printf("side is %.2lf\n",&side)
       getch();
       }
       else
       {
       printf("Error\n");
       getch();
       }
       }
    	}
       }\
    Shaun

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You have all kinds of horrid problems with this code. This should give you a start toward improving it:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main ( void )
    {
      double side, area;
      int count;
    
      for ( count = 0; count <= 5; count++ )
      {
        printf ( "Enter area:" );
        fflush ( stdout );
        scanf ( "%lf", &area );
        if ( ( area <= 10 ) && ( area >= 2 ) ) {
          side = sqrt ( area );
          printf ( "side is %.2f\n", &side );
        }
        else
          printf("Error\n");
      }
    
      return 0;
    }
    [edit]
    Salvaging my pride.
    [/edit]
    Last edited by Prelude; 03-17-2004 at 09:23 PM.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    10

    Its WORKING!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <math.h>
    
    // Variable List
    
    double side,area;
    int count;
    
    void main(void)
    
    {
    	clrscr();
       for(count=0;count<=5;count=count+1)
       {
       printf("Enter area:\n");
       scanf("%;f",&area);
       if((area<=10)&&(area>=2))
       {
       	side=sqrt(area);
       printf("side is %.2lf\n",&side);
       getch();
       }
       else
       {
       printf("Error\n");
       getch();
       }
       }
    	}
    Shaun

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    You know, you should take some time to have a close look at Prelude's code. She took the time to clean up some of it, and then you post code with some of her solutions, but got rid of some of her code also.... Compare what she has to what you have and learn.

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >fflush ( stdin );
    Umm... Prelude... are you feeling OK? I think (hope) you meant stdout.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    ergh... compare what she has and unlearn... lol

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Umm... Prelude... are you feeling OK?
    Gack! I was thinking void main and became tainted enough to write the other sinful construct.

    >I think (hope) you meant stdout.
    I did. If the fflush is after a printf then you can be sure I meant stdout. If the fflush is after a scanf then you can be sure I'm either describing how not to do it or I've gone insane.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM