Thread: help me. i have 3 error.

  1. #1
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57

    help me. i have 3 error.

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    char *str,select;
    
    main()
    {
    int item;
          do
          {
    		clrscr();
    		printf("1. FACTORIAL\n");
    		printf("2. FIBONACCI\n");
    		printf("3. EUCLID\n");
    		printf("4. EXIT\n");
    		printf("SELECT AN OPTION:\n");
    		scanf("%d",&item);
    		if (item==1)
    		{
    			clrscr();
    {
    long a,b,c;
    gotoxy(1,1);
    printf("RECURSIVE\n");
    printf("Enter a Number: ");
    scanf("%li",&a);
    c=1;
    b=1;
    do
    {
    printf("%li = %li*%li=%li\n",b,b,c,b*c);
    c*=b;
    b++;
    }while(b<=a);
    printf("FACTORIAL IS %li",c);
    }
    getch();
    }
    
    else if (item==2)
    		{	clrscr();
    {
    int f,a,b,c,ctr;
    gotoxy(1,1);
    printf("ITERATION\n");
    printf("ENTER A NUMBER: ");
    scanf("%d",&c);
    f=1;
    a=1;
    if(c<1)
    printf("TRY AGAIN");
    else
    printf("0\t");
    for(ctr=1;ctr<=c;ctr++)
    {
    printf("%d\t",f);
    if(ctr>1)
    {
    b=f+a;
    a=f;
    f=b;
    }
    }
    getch();
    }
    }
    
    		else if (item==3)
    
    		clrscr();
    		{
    		long a,b,q,r;
    		gotoxy(1,1);
    		do
    		{
    		printf("ENTER IST  NUMBER :");
    		scanf("%li",&a);
    		printf("ENTER 2ND NUMBER :");
    		scanf("li",&b);
    		}
    		while(b>a);
    		do
    		{
    		q=a/b;
    		r=a%b;
    		printf("%li=%li(%li)+li \n",a,b,q,r);
    		a=b;
    		b=r;
    		}
    		while(r>0);
    		printf("GCD is %li",a);
    		getch();
    		}
    		}
    			else if (item==4)
    			{
    			break;
    			}
    			else
    			{
    				printf("Invalid Input! Press Any Key to Continue...");
    				getch();
    			}
    		}while(item!="2");
    		getch();
    		}
    MY errors are.
    95: do statement must have while in function main.
    104: declaration syntax error
    106: declaration syntax error.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    * Fix your indenting, you're probably missing a bracket.
    * Avoid using conio.h and getch().

    Then your errors will disappear, or at least you'll be able to see them

  3. #3
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    why. avoid using getch. huhuhu help me please.

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    why. avoid using getch. huhuhu help me please.
    Because it's not portable.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    aha. so. what's wrong with my program.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Stop spamming the same question, starting new threads etc -- it's obvious this is an assignment. Fix your indenting then we'll work from there.

  7. #7
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    char *str,select;
    
    main()
    {
    int item;
          do
          {
    clrscr();
    printf("1. FACTORIAL\n");
    printf("2. FIBONACCI\n");
    printf("3. EUCLID\n");
    printf("4. EXIT\n");
    printf("SELECT AN OPTION:\n");
    scanf("&#37;d",&item);
    if (item==1)
    {
    clrscr();
    {
    long a,b,c;
    gotoxy(1,1);
    printf("RECURSIVE\n");
    printf("Enter a Number: ");
    scanf("%li",&a);
    c=1;
    b=1;
    do
    {
    printf("%li = %li*%li=%li\n",b,b,c,b*c);
    c*=b;
    b++;
    }while(b<=a);
    printf("FACTORIAL IS %li",c);
    }
    getch();
    }
    
    else if (item==2)
    {	
    clrscr();
    {
    int f,a,b,c,ctr;
    gotoxy(1,1);
    printf("ITERATION\n");
    printf("ENTER A NUMBER: ");
    scanf("%d",&c);
    f=1;
    a=1;
    if(c<1)
    printf("TRY AGAIN");
    else
    printf("0\t");
    for(ctr=1;ctr<=c;ctr++)
    {
    printf("%d\t",f);
    if(ctr>1)
    {
    b=f+a;
    a=f;
    f=b;
    }
    }
    getch();
    }
    }
    
    else if (item==3)
    
    clrscr();
    {
    long a,b,q,r;
    gotoxy(1,1);
    do
    {
    printf("ENTER IST  NUMBER :");
    scanf("%li",&a);
    printf("ENTER 2ND NUMBER :");
    scanf("li",&b);
    }
    while(b>a);
    do
    {
    q=a/b;
    r=a%b;
    printf("%li=%li(%li)+li \n",a,b,q,r);
    a=b;
    b=r;
    }
    while(r>0);
    printf("GCD is %li",a);
    getch();
    }}
    
    else if (item==4)
    {
    break;
    }
    else
    {
    printf("Invalid Input! Press Any Key to Continue...");
    getch();
    }
    }while(item!="2");
    getch();
    }

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    This is what your code should look like in your code editor, and what it should look like posted on a forum.
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    char *str, select;
    
    main()
    {
        int item;
        do {
            clrscr();
            printf("1. FACTORIAL\n");
            printf("2. FIBONACCI\n");
            printf("3. EUCLID\n");
            printf("4. EXIT\n");
            printf("SELECT AN OPTION:\n");
            scanf("%d", &item);
            if (item == 1) {
                clrscr();
                {
                    long a, b, c;
                    gotoxy(1, 1);
                    printf("RECURSIVE\n");
                    printf("Enter a Number: ");
                    scanf("%li", &a);
                    c = 1;
                    b = 1;
                    do {
                        printf("%li = %li*%li=%li\n", b, b, c, b * c);
                        c *= b;
                        b++;
                    } while (b <= a);
                    printf("FACTORIAL IS %li", c);
                }
                getch();
            } else if (item == 2) {
                clrscr();
                {
                    int f, a, b, c, ctr;
                    gotoxy(1, 1);
                    printf("ITERATION\n");
                    printf("ENTER A NUMBER: ");
                    scanf("%d", &c);
                    f = 1;
                    a = 1;
                    if (c < 1)
                        printf("TRY AGAIN");
                    else
                        printf("0\t");
                    for (ctr = 1; ctr <= c; ctr++) {
                        printf("%d\t", f);
                        if (ctr > 1) {
                            b = f + a;
                            a = f;
                            f = b;
                        }
                    }
                    getch();
                }
            } else if (item == 3)
                clrscr();
            {                       /*!! I bet this brace isn't where it should be */
                long a, b, q, r;
                gotoxy(1, 1);
                do {
                    printf("ENTER IST  NUMBER :");
                    scanf("%li", &a);
                    printf("ENTER 2ND NUMBER :");
                    scanf("li", &b);
                }
                while (b > a);
                do {
                    q = a / b;
                    r = a % b;
                    printf("%li=%li(%li)+li \n", a, b, q, r);
                    a = b;
                    b = r;
                }
                while (r > 0);
                printf("GCD is %li", a);
                getch();
            }
    
    
    /*!!
        else
    if (item == 4) {
        break;
    } else {
        printf("Invalid Input! Press Any Key to Continue...");
        getch();
    }
    !!*/
        } while (item != "2");
        getch();
    
    }
    If it doesn't, then work on that until you get it right. You've had 50 posts now, it's time you learnt this basic stuff.

    I've added a couple of comments to indicate where the braces are screwed up.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM