Pelles C forum

C language => Beginner questions => Topic started by: dnasty54 on September 30, 2014, 02:16:33 AM

Title: I dont know what im doing wrong
Post by: dnasty54 on September 30, 2014, 02:16:33 AM
/*
* calcute area of a rectangle.
*/
#include <stdio.h>               /* printf, scanf definitions */
#include <math.h>
int
main (void)
{
          double width,  /* input - width of rectangle. */
      double length, /* input - length of rectangle. */
      Area;    /* output - area of rectangle */

      /* get the width of rectangle. */
      printf("Enter width> ");
      scanf("%lf", &width);

      /* get the length of rectangle. */
      printf("Enter length> ");
      scanf("%lf", &length);

      /*convert to Area or rectangle. */
      Area  = width * length;
      
      /* display Area of rectangle. */
      printf( "The Area is %f . \n",  Area);

      return (0);

C:\Users\student\Documents\area.c(10): error #2092: Missing identifier.
C:\Users\student\Documents\area.c(10): error #2001: Syntax error; found 'double' expecting ';'.
*** Error code: 1 ***
Title: Re: I dont know what im doing wrong
Post by: Bitbeisser on September 30, 2014, 02:28:34 AM
Quote from: dnasty54 on September 30, 2014, 02:16:33 AM
/*
* calcute area of a rectangle.
*/
#include <stdio.h>               /* printf, scanf definitions */
#include <math.h>
int
main (void)
{
       double width,  /* input - width of rectangle. */
double length, /* input - length of rectangle. */
Area;    /* output - area of rectangle */

C:\Users\student\Documents\area.c(10): error #2092: Missing identifier.
C:\Users\student\Documents\area.c(10): error #2001: Syntax error; found 'double' expecting ';'.
*** Error code: 1 ***
Well, just read the error messages, they point exactly to the problem, in particular the second one... :!:
Correctly the snippet would be written
       double width;  /* input - width of rectangle. */
double length; /* input - length of rectangle. */
double Area;    /* output - area of rectangle */
Punctuation to terminate statements matters!  ;)

Ralf
Title: Re: I dont know what im doing wrong
Post by: dnasty54 on September 30, 2014, 02:41:22 AM
now i have those same errors twice!!  :-[ :-[
Title: Re: I dont know what im doing wrong
Post by: Bitbeisser on September 30, 2014, 02:45:08 AM
Quote from: dnasty54 on September 30, 2014, 02:41:22 AM
now i have those same errors twice!!  :-[ :-[
Post your complete code, surrounded by code tags, please...

Ralf
Title: Re: I dont know what im doing wrong
Post by: dnasty54 on September 30, 2014, 02:49:07 AM
nevermind i see what u were saying about the ;'s thanks alot!!
Title: Re: I dont know what im doing wrong
Post by: mtazy on October 02, 2014, 06:41:30 AM
#include <stdio.h>
#include <math.h>
int main (void)
{
   double width;
   double length;
        double Area;

      /* get the width of rectangle. */
      printf("Enter width> ");
      scanf("%lf", &width);

      /* get the length of rectangle. */
      printf("Enter length> ");
      scanf("%lf", &length);

      /*convert to Area or rectangle. */
      Area  = width * length;
     
      /* display Area of rectangle. */
      printf( "The Area is %f . \n",  Area);

      return 0;
}

*make sure that when u open a brace, u close it after your 'return 0;'
*clearly read the errors, double-click each to see in which line the error is
*each instruction ends by a ';' not a ','