help with c# program

tmh88tmh88 Pittsburgh / Athens, OH
edited January 2007 in Internet & Media
Hey guys I'm working on a C# program that gets the X and Y input from a user, and then determines which quadrant the x,y is in. It needs to determine the position of the point as a function of the two paramaters, x and y. Heres what I have so far. Can you guys give me some suggestions how to fix the errors? thanks

i realize that I need to call the function from below, but I cant think of any simple ways to do it.

and btw #include <stdio.h isnt showing up in the code down below for some reason, but its there, just trust me on it.
#include <stdio.h>


int main (void) {

double x,y;

printf("Enter the X value");
scanf("%lf", &x);

printf("Enter the y value");
scanf("%lf", &y);
return (0);
}


{
double x,y;

if (x==0 && y==0)
   printf("The point is on the origin");
else

if (x==0)
  printf("The point is on the X axis");
else

if (y==0)
   printf("The point is on the Y axis");

else

if (x>0 && y>0)
   printf("The point is in quadrant 1");

else

if (x<0 && y>0)
   printf("The point is in quadrant 2");

else

if (x<0 && y<0)
   printf("The point is in quadrant 3");

else

if (x>0 && y<0)
   printf("The point is in quadrant 4");

return (0);
}

when I compile it I get the error l
ab4.c:25: error: expected identifier or '(' before '{' token

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    you need to name your function, so you can call it after you have the x,y inputs:
    int aFunctionName (whatever your arguments are {it might be good to pass it x and y}) {
    double x,y;
    
    if (x==0 && y==0)
       printf("The point is on the origin");
    else
    
    if (x==0)
      printf("The point is on the X axis");
    else
    
    if (y==0)
       printf("The point is on the Y axis");
    
    else
    
    if (x>0 && y>0)
       printf("The point is in quadrant 1");
    
    else
    
    if (x<0 && y>0)
       printf("The point is in quadrant 2");
    
    else
    
    if (x<0 && y<0)
       printf("The point is in quadrant 3");
    
    else
    
    if (x>0 && y<0)
       printf("The point is in quadrant 4");
    
    return (0);
    }
    
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited January 2007
    Ok i re-wrote it and it runs perfectly
    #include <stdio.h>
    
    double coordinate (double, double);
    int main (void) {
    double x,y;
    	printf("Enter the X value\n");
    	scanf("%lf", &x);
    	printf("Enter the y value\n");
    	scanf("%lf", &y);
    	
    	printf("%1.2f", coordinate (x, y));
    
    return (0);
    }
    
    double coordinate (double x, double y) {
    if (x == 0 && y == 0)
            printf("The point is on the origin.\n");
    else
    if (x == 0 && y > 0)
            printf("The point is on the positive y axis.\n");
    else
    if (x == 0 && y < 0)
            printf("The point is on the negative y axis.\n");
    else
    if (y == 0 && x > 0)
            printf("The point is on the positive x axis.\n");
    else
    if (y == 0 && x < 0)
            printf("The point is on the negative x axis.\n");
    else
    if (x > 0 && y > 0)
            printf("The point is in quadrant 1.\n");
    else
    if (x < 0 && y > 0)
            printf("The point is in quadrant 2.\n");
    else
    if (x < 0 && y < 0)
            printf("The point is in quadrant 3.\n");
    else
    if (x > 0 && y < 0)
            printf("The point is in quadrant 4.\n");
    return (0);
    }
    
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    do you need to return anything? If not, why are you returning something?
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited January 2007
    it prints out what quadrant or axis the points are on.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    right, but everytime you call the function, it returns the same (useless) value (0), regardless of what you pass it. Why bother to return something?
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited January 2007
    idk, but it still works the way I want it to so im not gonna mess with it.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    I'd take points off if I were grading it. You know, if I were a TA.
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited January 2007
    So, are you suggesting to get rid of printf() and replace that with return (coordinate) or something?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    I'm saying don't return anything.
Sign In or Register to comment.