Thread: HELP problem in function main.

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

    HELP problem in function main.

    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();
    		}

    i have 1 error.
    95: do statement must have while in function main,
    help me guys please. just 1 errror.

  2. #2
    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();
    }
    error.
    95: do statement must have while in function main
    please help. i really need this tomorow.

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Maybe you could start by indenting your code to see where all your opening and closing braces match? I cant be bothered to do it for you.

  4. #4
    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();
    }}
    {        /* do statement must have while in function main */
    else if (item==4)
    {
    break;
    }
    else
    {
    printf("Invalid Input! Press Any Key to Continue...");
    getch();
    }
    }while(item!="2");
    getch();
    }
    help me...

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Now you're just spamming.

  6. #6
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    im sorry. please help me. just 1 error. huhuhu. what will i do.

  7. #7
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    If you dont indent your code its really hard for other people to see whats going on inside it. It should look something like:
    Code:
    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();
    Etc...

    Your teacher would also like to see it indented, and will probably give you better marks for it. You will have much more chance of getting help here if you indent your code first

  8. #8
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    i dont know how. if only i know i would not help. is just that my prof. is not teaching us. he just want to make his program. even the code he dont teach. its for us to find out. thats why im here for help not for insult. thank you. ihope someone will help me.

  9. #9
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Fifty-two posts and still haven't learn how to post your code with the proper tags and indentation. Right now is very hard to read.
    I suggest you to start giving some serious consideration to the rules of the forum.
    Show some appreciation for the help given by posting correctly next time.

    Code:
    You have a problem with the {} brackets. Start looking from if (item==1)

  10. #10
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    i dont know how. if only i know i would not ask help. is just that my prof. is not teaching us. he just want to make his program. even the code he dont teach. its for us to find out. thats why im here for help not for insult. thank you. ihope someone will help me....
    so please help me.

  11. #11
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Hey, I'm not insulting you; I'm telling what you should do first in order to sort out your code.

  12. #12
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    okay. im sorry. please help me with my project. what's wrong with my program.

  13. #13
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Seriously, stop spamming the same question. Salem even indented and commented on your code on your last topic, http://cboard.cprogramming.com/showthread.php?t=96446

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    There is a preview function for when you post the message, except it's the button next to the post message button. click on that instead of the post message button, until you get it right.

    to indent your code, just press the space bar before the line until it gets far enough to the right.

    For the Quick Reply box, click the Go Advanced button. it's the same thing as the Preview button.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh for darn sake, if you want help then LISTEN to what we tell you.
    Intend that code already so we can READ it!
    Posting help help help help help all the time WON'T help you, because we've already helped you a bit by telling you what you should do but you're not LISTENING.
    And if you can't code, then we can't help you. This is a programming forum, not a homework forum.
    There's lots of tutorials on the site too, if you need help with something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM