Syntax error at end of input - only last curly brace highlighted ??

This is a discussion on Syntax error at end of input - only last curly brace highlighted ?? within the C Programming forums, part of the General Programming Boards category; Code: Hi all! I got a problem with my code. Unfortunately, I have to submit this assignment tmr, so I ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    5

    Syntax error at end of input - only last curly brace highlighted ??

    Code:
    Hi all! 
    
    I got a problem with my code. Unfortunately, I have to submit this assignment tmr, so I really need help, >.< Here is the code :
    
    /* This program is used to determine how deep the water will be when 1000 cubic feet per second is flowing through the channel based on user's guess*/
    #include <stdio.h> /* define printf and scanf */
    #include <math.h> /* define mathematical operations */
    #define N 0.014
    #define W 15
    #define cons 1.486
    
    double area (double depth) ;
    double hydraulic_radius (double depth , double cross_area) ;
    double flow (double cross_area, double power_radius, double power_S) ; /* define function named flow */
    double pow(double radius, double Y_1) ;
    double pow(double S, double Y_2) ;
    
    main() 
    {
      /* define variable that will be used */     
      double depth  ; /* variable named depth, with type = double */
      double cross_area ;
      double radius ; 
      double waterflow ;
      double Y_1 ;
      double Y_2 ;
      double power_radius ;
      double power_S ;
      double S ;
        
      /* mention the background and the purpose of the program */
      printf ("A concrete channel to bring water to a lake is being designed \n") ; 
      printf ("It will have vertical walls and be 15 ft wide, 10 ft deep, have a slope 0.0015, and a roughness coefficient 0.014 \n") ;
      printf ("This program will determine how deep the water will be when 1000 cubic feet per second is flowing through the channel . \n") ;
      printf ("Users are requested to guess a depth. \n") ;
      
      /* get the depth guessing from user */
      printf ("Input your guess for the depth of the water in the channel ---> ") ;
      
      /* store the inputted value in variable named depth */
      scanf ("%lf", &depth) ;
      
      
      while (10 <= depth)
    {
    printf ("Invalid guess. \n");
    printf ("Your guess is exceeding the channel depth. \n");
    printf ("Please input again your guess for the depth of the water in the channel ---> ");
    scanf ("%lf", &depth) ;
    }
      
        
      cross_area = area (depth) ;
      
      radius = hydraulic_radius (depth , cross_area) ;
      
      Y_1 = 2.0/3.0 ;
      power_radius = pow (radius , Y_1) ;
      
      S = 0.0015 ;
      Y_2 = 1.0/2.0 ;
      power_S = pow (S , Y_2) ;
      waterflow = flow (cross_area, power_radius, power_S) ;
      
      while (1001 <= waterflow)
    {
    printf ("Incorrect depth. Please guess a little lower. \n");
    printf ("Please input again your guess for the depth of the water in the channel ---> ");
    scanf ("%lf", &depth) ;
    }
      
      while (waterflow <= 999)
    {
    printf ("Incorrect depth. Please guess a little higher. \n");
    printf ("Please input again your guess for the depth of the water in the channel ---> ");
    scanf ("%lf", &depth) ;
    }
      
      {printf ("Yeah! You got it! CONGRATULATION! ^0^ \n");
      {printf ("%9.3f is the deep of the water when %9.3f cubic feet of water per second is flowing through the channel \n", depth,flow);
      
      
      system ("PAUSE") ;
      return 0 ;
    }
    
    
    
    
    double area (double depth)
    {
           return (depth*W) ;
    }
    
    double hydraulic_radius (double depth, double cross_area)
    {
           return (cross_area/(2*depth + W)) ;
    }
    
    /* function named flow, used to calculate the water flow based on Manning's equation */
    double flow (double power_radius, double cross_area, double power_S)
    {
           return ((cons/N)*cross_area*power_radius*power_S) ;
    }
    
    
    When I tried to compile them, the program keep highlighting the last curly brace, and sending error message "syntax error at end of input". I don't know what to do, since I'm new in C programming. (and here as well, so I'm terribly sorry if my post doesn't really follow the guidelines, I skipped reading some of them since I'm in a bit hurry,,,so sorry,,,I'm going to read it after this though,,,)
    
    Anyone that could help? Thank you so much before. ^^

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is your program with a few kinks worked out. You had two too many { braces, and the logic needed a bit of touch up.

    Code:
    /*
    
    I got a problem with my code. Unfortunately, I have to submit this 
    assignment tmr, so I really need help, >.< Here is the code :
    
    This program is used to determine how deep the water will be when 1000 cubic
    feet per second is flowing through the channel based on user's guess
    */
    
    #include <stdio.h> /* define printf and scanf */
    #include <math.h> /* define mathematical operations */
    #define N 0.014
    #define W 15
    #define cons 1.486
    
    double area (double depth) ;
    double hydraulic_radius (double depth , double cross_area) ;
    double flow (double cross_area, double power_radius, double power_S) ; /* define function named flow */
    double pow(double radius, double Y_1) ;
    double pow(double S, double Y_2) ;
    
    int main() 
    {
      /* define variable that will be used */     
      double depth  ; /* variable named depth, with type = double */
      double cross_area ;
      double radius ; 
      double waterflow ;
      double Y_1 ;
      double Y_2 ;
      double power_radius ;
      double power_S ;
      double S ;
        
      /* mention the background and the purpose of the program */
      printf ("A concrete channel to bring water to a lake is being designed \n") ; 
      printf ("It will have vertical walls and be 15 ft wide, 10 ft deep, have a slope 0.0015, and a roughness coefficient 0.014 \n") ;
      printf ("This program will determine how deep the water will be when 1000 cubic feet per second is flowing through the channel . \n") ;
      printf ("Users are requested to guess a depth. \n") ;
      
      waterflow = 0.0;
      while((waterflow >= 1001) || (waterflow <= 999)) 
      {
        /* get the depth guessing from user */
        printf ("Input your guess for the depth of the water in the channel ---> ") ;
      
        /* store the inputted value in variable named depth */
        scanf ("%lf", &depth) ;
      
        if(depth >= 10.1)
        {
          printf ("\nInvalid guess. \n");
          printf ("Your guess exceeds the depth of the channel. \n");
        }
        else {
          cross_area = area (depth) ;
          radius = hydraulic_radius (depth , cross_area) ;
          Y_1 = 2.0/3.0 ;
          power_radius = pow (radius , Y_1) ;
          S = 0.0015 ;
          Y_2 = 1.0/2.0 ;
          power_S = pow (S , Y_2) ;
          waterflow = flow (cross_area, power_radius, power_S) ;
      
          if(waterflow >=1001.0) 
            printf ("\nIncorrect depth. Please guess a little lower. \n");
          else if (waterflow <= 999)
            printf ("\nIncorrect depth. Please guess a little higher. \n");
          else 
          {
            printf ("\nYeah! You got it! CONGRATULATION! ^0^ \n");
            printf ("\n%9.3f feet, is the depth of the water when %9.3f cubic feet of \nwater per second is flowing through the channel \n", 
    
    depth,waterflow);
          }
        }
      }
            
      system ("PAUSE") ;
      return 0 ;
    }
    
    double area (double depth)
    {
      return (depth*W) ;
    }
    
    double hydraulic_radius (double depth, double cross_area)
    {
      return (cross_area/(2*depth + W)) ;
    }
    
    /* function named flow, used to calculate the water flow based on Manning's equation */
    double flow (double power_radius, double cross_area, double power_S)
    {
      return ((cons/N)*cross_area*power_radius*power_S) ;
    }
    Thanks for using code tags. Please keep all text inside code tags to < 70 char's in any one line. Otherwise it "breaks" the width of the forum for displaying code, and makes it very difficult to read the program.

    And welcome to the forum.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Here's a tip.

    Do not write
    Code:
    for ( i = 0 ; i < 10 ; i++ ) {
    then write a whole bunch of code,
    then hope to write (possibly hours later, if you got distracted)
    Code:
    }
    You will screw this up on a regular basis.



    Instead, write this
    Code:
    for ( i = 0 ; i < 10 ; i++ ) {
    }
    then move the cursor back inside the loop braces and start typing the rest of your code.
    EVERY brace will always be in the right position right from the start.

    Same goes for /**/, ( ), " ". If the empty sequences start off being balanced to begin with, then you don't have to waste lots of effort trying to repair it later on.

    Some of the more feature rich IDEs will do all of this for you, so the cost to you is in fact zero.
    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.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    5
    Adak & Salem, thx bunches for your kind help! I'll keep your advices in mind for my next assignment. =D
    Last edited by Salem; 03-07-2010 at 06:50 AM. Reason: Removed code tags - that's a new one

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Can you stick to putting [code][/code] tags around things which are actually code.
    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. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  5. How can I read until the end of an input line?
    By Bad_Scooter in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2003, 09:29 PM

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