Thread: i give up

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    12

    i give up

    This is a program im trying to get to work for my test :-(

    Code:
      #include <stdio.h>
    
    int main (void)
     
     {  
    
     float value1; 
     
    float accumulator = 0;  
     
    char operator;   
    
     
    
    
    
    printf ("\t\tCalulator\n");  
     
    printf ("\t\t---------\n");   
    
    
    printf("Type in your test\n"); 
    
    scanf("%f %c", &value1, &operator);    
     
    
    do
    {
    
    
    switch (operator) 
    
      {
     
     case 'S':      
     
    accumulator = value1;   
     
    printf("%.3f\n", value1);     
    
     break;        
    
    
    
     case 's':       
    
     accumulator = value1;     
     
    printf("%.3f\n", value1);      
     
    break;        
    
    
    
     case '+':      
    
     accumulator += value1;      
    
     printf("%.3f\n", accumulator);       
     
    break;       
    
     
    
     case '-':       
    
     accumulator = accumulator - value1;      
    
     printf("%.3f\n", accumulator);       
     
    break;        
    
    
    
    case '/':      
    
    accumulator = accumulator / value1;      
     
    printf("%.3f\n", accumulator);       
     
    break;       
    
     
    
    case '*':       
    
     accumulator = accumulator * value1;       
    
    printf("%.3f\n", accumulator);                 
    
    break;        
    
    
    
     case 'E':        
    
     printf("End of Tests\n");       
     
    break;        
    
    
    
     case 'e':      
     
    printf("End of Tests\n");       
     
    break;             
    
    
    
     default:      
     
    printf("UNKNOWN OPERATOR\n");     
      
    break;
    
    }
    
    while (operator != 'e' && operator != 'E')
    
    
    
    printf("\n%.3f\n", accumulator);
    	
    
    
    	
    
    return 0;
    
    }
    
    //compiling error
    prog6.4.c: In function ‘main’:
    prog6.4.c:72: error: expected expression before ‘}’ token
    prog6.4.c:79: error: expected ‘while’ at end of input
    prog6.4.c:79: error: expected declaration or statement at end of input

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Learn to indent your code correctly and the missing brace should be obvious.

    Tim S.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    //compiling error
    prog6.4.c: In function ‘main’:
    prog6.4.c:72: error: expected expression before ‘}’ token
    prog6.4.c:79: error: expected ‘while’ at end of input
    prog6.4.c:79: error: expected declaration or statement at end of input
    Do what the rest of us do... address each error one at a time, recomiple and try again, until they're all gone...

    Some things that will help you...
    Turn on line numbering in your IDE... the error messages contain line numbers.
    If you don't have it get an IDE that does brace matching, get one... it will show you any mismatches.
    Especially don't get all flustered because of compile errors. I'm sure we all deal with them all the time.
    Last edited by CommonTater; 03-31-2011 at 06:42 PM.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    12
    can get through this error
    prog6.4.c: In function ‘main’:
    prog6.4.c:78: error: expected ‘while’ before ‘return’

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by leahknowles View Post
    can get through this error
    prog6.4.c: In function ‘main’:
    prog6.4.c:78: error: expected ‘while’ before ‘return’
    Indent your code and you will see you are not closing both the switch and the do statement.
    Try to do some work or fail!

    Tim S.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Give me some opinions on setting up a server
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 04-19-2004, 10:38 AM
  2. Can you give me your tip plz :)
    By dionys in forum C Programming
    Replies: 6
    Last Post: 04-11-2004, 11:14 PM
  3. Can you give me an example of a new line character?
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 04-10-2003, 11:59 AM
  4. How To Give A Font Colour ?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 09-14-2001, 01:22 PM
  5. Just to give you an idea of what we're going through...
    By rick barclay in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-13-2001, 02:09 PM