help me i have 3 errors ,

This is a discussion on help me i have 3 errors , within the C++ Programming forums, part of the General Programming Boards category; 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"); ...

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

    help me i have 3 errors ,

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

  2. #2
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    Please format your code and post what your program does along with the errors.

    [edit] After pasting your code in Dev C++ I think you will see many of your errors. Your braces are out of place.
    Last edited by Loctan; 11-30-2007 at 09:16 PM.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Based on the menu, I'd say the program outputs recurcive sequences, or something like that. Isn't this C code?

  4. #4
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    MY errors are.
    95: do statement must have while in function main.
    104: declaration syntax error
    106: declaration syntax error.

  5. #5
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    YES its a C code.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    Then why post it in the C++ forum ?

    Your code is almost unreadable because of (very) poor indentation. It's also what is causing you those errors. If your code was properly indented, you would have seen the errors. You're missing a while() at the end of a do...while() which is causing you the first error. I'd say the two others are causing by missing or incorrect braces. You may also want to space out everything a little bit and make functions for output.

    Edit:

    Note that calling main without a return type is poor coding style. It should be "int main()" or "int main(int, char**)" and nothing else.

    Edit #2:

    There are many things that will produce unwanted behavior such as while(item!="2"); which basically mean "while item is not 50". I'll let you find out why. There is also a possible case of divide by zero, which is illegal. You are also defining 3 or 4 different variables with the same name which is awful.

    Edit #3:

    Oh, and you're not using those globals at the top.
    Last edited by Desolation; 11-30-2007 at 10:43 PM.

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    She already posted the same thing twice in the C forum.

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    People like this shouldn't be allowed to post on forums. At least they'll fail their programming course.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    Here as well - help me. i have 3 error.
    When someone tells you it's in the wrong forum, wait for a mod to move it.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  4. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21