Results 1 to 13 of 13

Thread: Little bit of help in C would be appreciated

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Thanks
    0
    Thanked
    0 times in 0 posts

    Little bit of help in C would be appreciated

    Hello all,

    Ive just started some coding at uni in c and have written one of my programs up, im down to one error which i can not seem to remove no matter what i do! This is very basic c i guess, probably a little error but its frustrationg me!

    Code:
    /*****************************************************************
     Author: Michael R
     Date: 22nd March 2005
     Purpose: Assignment One - Validating Triangle Sizes
    *****************************************************************/
    
    #include <stdio.h>
    
    int main ()
    {
         int firstside;
         int secondside;
         int thirdside;
        
         printf("Enter the value of the first side of the triangle: ");
         scanf("%d", &firstside);
    
         printf("Enter the value of the second side of the triangle: ");
         scanf("%d", &secondside);
    
         printf("Enter the value of the third side of the triangle: ");
         scanf("%d", &thirdside);
         
         
            if { ((firstside == secondside) && (firstside == thirdside) && (secondside == thirdside)) 
            printf("The first side inputed was %d\n", firstside);
    	printf("The second side inputed was %d\n", secondside);
            printf("The third side inputed was %d\n", thirdside);
            printf("As a result this is a equilateral triangle as all three sides are of equal length.");
               }    
               
            else
    	   if { ((firstside == secondside) || (firstside == thirdside) || (secondside == thirdside))
        	   printf("The first side inputed was %d\n", firstside);
    	   printf("The second side inputed was %d\n", secondside);
               printf("The third side inputed was %d\n", thirdside); 
               printf("As a result this is a Isosceles triangle as two of the three sides are of equal length.");
                  } 
              
                else
    	       if { ((firstside != secondside) && (firstside != thirdside) && (secondside != thirdside))
    	       printf("The first side inputed was %d\n", firstside);
    	       printf("The second side inputed was %d\n", secondside);
                   printf("The third side inputed was %d\n", thirdside); 
    	       printf("As a result this triangle has no sides of equal length and hence is a scalene triangle.");
                      }
    
                  else 
                      printf("The first side inputed was %d\n", firstside);
    		  printf("The second side inputed was %d\n", secondside);
                      printf("The third side inputed was %d\n", thirdside); 
                      printf("The inputed sides do not create a  valid triangle as the addition two sides are not greater than the third side ");	
                       
    
         return(0);
    }
    The error i am recieving is on line 25 the first if statement I cant seem to remove it, this is the output i get when trying to compile.

    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    g:\ict102\assessment1\test.c:
    Error E2376 g:\ict102\assessment1\test.c 25: If statement missing ( in function main
    *** 1 errors in Compile ***


    If any1 could steer me in the right direction it would be a great help.

    Cheers,

    Michael

  2. #2
    LWA
    LWA is offline
    Senior Member
    Join Date
    Jul 2003
    Location
    London
    Posts
    2,171
    Thanks
    134
    Thanked
    57 times in 41 posts
    IIRC a C if loop should be written:

    if (Condition)
    {
    do some code
    }

    Your curly brackets are not outside of the loop condition.

    So

    Code:
    if ((firstside == secondside) && (firstside == thirdside) && (secondside == thirdside))
    { 
            printf("The first side inputed was %d\n", firstside);
    	printf("The second side inputed was %d\n", secondside);
            printf("The third side inputed was %d\n", thirdside);
            printf("As a result this is a equilateral triangle as all three sides are of equal length.");
    }
    Hope this helps,
    Leon

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Thanks
    0
    Thanked
    0 times in 0 posts
    ahhh cheers for that

    i havent done the loops yet only started the course recently

    Much appreciated

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Before you go any other it should be pointed out that an if...else statement is NOT a loop, don't go away thinking that it is!
    To err is human. To really foul things up ... you need a computer.

  5. #5
    LWA
    LWA is offline
    Senior Member
    Join Date
    Jul 2003
    Location
    London
    Posts
    2,171
    Thanks
    134
    Thanked
    57 times in 41 posts
    Quote Originally Posted by spitty!
    ahhh cheers for that

    i havent done the loops yet only started the course recently

    Much appreciated
    Anytime mate, here at Hexus you will always find people willing to help

  6. #6
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    Quote Originally Posted by yamangman
    Before you go any other it should be pointed out that an if...else statement is NOT a loop, don't go away thinking that it is!
    lmao so true. That's the true programming peril, not understanding something

  7. #7
    Theoretical Element Spud1's Avatar
    Join Date
    Jul 2003
    Location
    North West
    Posts
    7,508
    Thanks
    336
    Thanked
    320 times in 255 posts
    • Spud1's system
      • Motherboard:
      • Gigabyte Aorus Master
      • CPU:
      • 9900k
      • Memory:
      • 16GB GSkill Trident Z
      • Storage:
      • Lots.
      • Graphics card(s):
      • RTX3090
      • PSU:
      • 750w
      • Case:
      • BeQuiet Dark Base Pro rev.2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Asus PG35VQ
      • Internet:
      • 910/100mb Fibre
    you can also declare variables of the same type all on one line, like this (if you want to)

    Code:
          int firstside, secondside, thirdside;
    Not a vital thing, but its good programming practice, makes it ever so slightly faster to compile and read

  8. #8
    Senior Member
    Join Date
    Feb 2005
    Location
    Folsom, CA
    Posts
    221
    Thanks
    0
    Thanked
    0 times in 0 posts
    Out of curiosity what class was it for? I just got my Bachelors in CS from UC Davis here in California.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Thanks
    0
    Thanked
    0 times in 0 posts
    arrrrgg, its getting me so frustrated i still cant get it work, properly. oh well ill leave it for a few days and come back to it.

    Im trying to do another one for uni with while loops, same errors keep on plauging my code that i cant remove!

    Im in First Year uni, the course is "intro to computer science" im doing a networking degreee

    I wish that my tutor had time to look and help me with my work, when ever she gets aroudn to me, the tutorial is over, so im fending on my own

    My latest attempt at a new program for one of my tut's

    Code:
    /*****************************************************************
     Author: Michael R
     Date: 30th March 2005
     Purpose: ASCII Values
    *****************************************************************/
    
    #include <stdio.h>
    
    
    int main ()
    {
    	int mychar, uppercase, lowercase;
            
          	printf("Please enter a letter of the alphabet for the ASCII value of the haracter:");
         	printf("Alternatively enter # to exit this program");
            scanf("%c%*c", &mychar);
    
    	uppercase = mychar + 32;
    	lowercase = mychar - 32;
           	
    	while(mychar =! '#')
            {
                   	if { (65<= mychar <=90)  
    	 	printf("The ASCII value is equal to %d and as a capital letter is equal to %d\n" mychar, uppercase);
                   	   }
    	
                      	if { (92<= mychar <=122)
    			printf(" The ASCII value is equal to %d and as a lowercase letter is equal to %d\n" mychar, lowercase);  	
                               }
                                 	
                         else{
                         printf("The user input is not a valid character, please try again");
    	                  }
            		printf("Please enter a letter of the alphabet for the ASCII value of the character:");
         			printf("Alternatively enter # to exit this program");
           			scanf("%c%*c", &mychar);
    
    			uppercase = mychar + 32;
    			lowercase = mychar - 32;
    	}     
    		return(0);
    }
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    g:\ict102\lab\week4lab\ascii.c:
    Warning W8060 g:\ict102\lab\week4lab\ascii.c 21: Possibly incorrect assignment in function main
    Error E2376 g:\ict102\lab\week4lab\ascii.c 23: If statement missing ( in function main
    Warning W8004 g:\ict102\lab\week4lab\ascii.c 43: 'lowercase' is assigned a value that is never used in function main
    Warning W8004 g:\ict102\lab\week4lab\ascii.c 43: 'uppercase' is assigned a value that is never used in function main
    *** 1 errors in Compile ***


    Can any1 explain these warnings :S or why it doesn't want to accept my while function
    Last edited by spitty!; 30-03-2005 at 03:10 AM.

  10. #10
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Heheh, you've made the same mistake as before, your curly braces come AFTER REPEAT AFTER the condition in an if statement (see big leons original post). Additionally, it appears your if statement conditions are incorrect. You have also unnecessarily reproduced code in your while loop.

    Get used to not getting help from tutors. Buy a book, do some research and figure it out on your own. If people do help, actually listen and take in what they say though.
    To err is human. To really foul things up ... you need a computer.

  11. #11
    Registered User
    Join Date
    Mar 2005
    Posts
    7
    Thanks
    0
    Thanked
    0 times in 0 posts
    The while loop test should be '!=' not '=!'.

  12. #12
    Moderator DavidM's Avatar
    Join Date
    Jan 2005
    Posts
    8,779
    Thanks
    802
    Thanked
    252 times in 234 posts
    Thats the trouble with compilers, the error doesnt make itself obvious immediately like code acted on on run-time. (As a former assembly language coder, you have my sympathies!)

  13. #13
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Thanks
    0
    Thanked
    0 times in 0 posts
    cheers for the advice guys, im gonna dive back into the pool of c and see what i can do

    Yeah i think i might buy another book when i have the finances, my text book for the course is like 100% algorithims hehe i need another1 on jus code

    ive finnished c now for the semester one ive done these last things, next week its onto java

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. good bit torrent client...with no spyware
    By cm_uk in forum Software
    Replies: 24
    Last Post: 23-07-2004, 12:46 PM
  2. When is 64 bit windows due?
    By wedge22 in forum Software
    Replies: 15
    Last Post: 18-06-2004, 02:45 PM
  3. Nintendo Boss a tad bit annoyed...
    By Devilbod in forum Gaming
    Replies: 15
    Last Post: 14-06-2004, 06:01 PM
  4. a teeny bit o' help...please?
    By shiato storm in forum General Discussion
    Replies: 11
    Last Post: 25-05-2004, 07:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •