You are here:

C++/Need HELP

Advertisement


Question
/* area.c */
#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include "stdlib.h"
#include "time.h"
#define C BLUE
#define B LIGHTGREEN
#define ESC 0x1b
#define N 50         /* Cantidad maxima de vertices */

main()
{
  int i,j,Xmi,Xma,Ymi,Yma,Mx=600,My=480,dX,dY;
  int gd=DETECT,gm;
  int n1,n2,c;
  char ch;
  long LN,S0,SL,li;
  int fig1[2*N];
  int fig2[2*N];

  clrscr();
  textcolor(LIGHTCYAN);
  cprintf("METODOS NUMERICOS");
  textcolor(LIGHTCYAN);
  cprintf("\nPROYECTO FINAL");
  textcolor(LIGHTCYAN);
  cprintf("\n          ");
  getch();
  clrscr();
  printf("Calculo de area de la figura azul\n\n");
  printf("Cantidad de vertices para la figura 1 (<%d): ",N);
  scanf("%d",&n1);
  clrscr();
  for(i=0;i<n1;i++)
  {
     printf("X[%2d] Y[%2d]: ",i+1,i+1);
     scanf("%d %d",&fig1[2*i], &fig1[2*i+1]);
  }
  clrscr();
  printf("cantidad de vertices para la figura 2 (<%d): ",N);
  scanf("%d",&n2);
  clrscr();
  for (i=0;i<n2;i++)
  {
     printf("X[%2d] Y[%2d]: ",i+1,i+1);
     scanf("%d %d", &fig2[2*i], &fig2[2*i+1]);
  }
  Xmi=Mx; Ymi=My; Xma=Yma=0;
  for(i=0;i<n2;i++)
  {
     Xmi=(Xmi > fig1[2*i])?fig1[2*i]:Xmi;
     Ymi=(Ymi > fig1[2*i+1])?fig1[2*i+1]:Ymi;
     Xma=(Xma < fig1[2*i])?fig1[2*i]:Xma;
     Yma=(Yma < fig1[2*i+1])?fig1[2*i+1]:Yma;
  }
  dX=Xma-Xmi+1; dY=Yma-Ymi+1;    /* anchura y altura del rectangulo */
  rpt:
  clrscr();
  printf("Cantidad de puntos para calcular: ");
  scanf("%ld",&LN);

  initgraph(&gd, &gm, "c:\\tc2\prg");

  setcolor(C);
  setfillstyle(BKSLASH_FILL,C);
  fillpoly(n1,fig1);
  setfillstyle(SOLID_FILL,BLACK);
  fillpoly(n2,fig2);
  setlinestyle(DASHED_LINE,1,1);
  setcolor(B);
  rectangle(Xmi-1,Ymi-1,Xma+1,Yma+1);
  setcolor(LIGHTCYAN);
  outtextxy(400,10,"ESC - salir, * - continuar.");
  if((ch=getch())==ESC) { closegraph(); exit(1); }
  outtextxy(400,20,"Espere mientras se calcule");

  randomize();
  SL=S0=0L;
  for(li=0;li<LN;li++)
  {
     i=Xmi + random(dX);
     j=Ymi + random(dY);
     if((c=getpixel(i,j))==C) SL++;
     putpixel(i,j,LIGHTRED);
  }
  getch();
  closegraph();
  clrscr();
  textcolor(BLUE);
  gotoxy(20,5);
  cprintf("Resultados de calculo:");
  textcolor(WHITE);
  gotoxy(20,7);
  cprintf("Area de rectangulo = %ld  (dX=%d X dY=%d)",(long)dX*dY,dX,dY);
  gotoxy(20,9);
  cprintf("Cantidad de puntos en el rectangulo: %ld",LN);
  gotoxy(20,11);
  cprintf("Cantidad de puntos en la figura:          %ld",SL);
  textcolor(RED);
  gotoxy(20,13);
  cprintf("Area relativa  (SL/LN):          %6.4f", ((double)SL)/LN);
  getch();
  textcolor(GREEN);
  clrscr();
  printf("Repetir calculo para otra cantidads de puntos? * - si, ESC - no");
  if((ch=getch()) != ESC) goto rpt;
}

This program has 2 errors: Line 54 and line 83: 'if stamente missing ) in function main'
If I have checked that parenthesis is ok, why i still have this error?


Answer
Hi I am sorry for delaying your answer!
But, I have devC++ compiler! Which does not support graphics.com. I have to get another compiler. I will reply to you as soon as possible

Hi can you do the assignment outside the if statement and check once more!

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


rakshitha

Expertise

Difficult questions related to C .

Experience

C ,vc ,opc ,windows CE, ActiveX

Education/Credentials
Masters in electrical engineering

©2016 About.com. All rights reserved.