I'm confused about "parse error"

This is a discussion on I'm confused about "parse error" within the C++ Programming forums, part of the General Programming Boards category; I am writing a program that converts celsius to farenhiet and vice versa. I made two function's that do the ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    9

    I'm confused about "parse error"

    I am writing a program that converts celsius to farenhiet and vice versa. I made two function's that do the converting for me so that all I have to do is call them like this:
    <code>
    (line 29) result = farenhiet_(float cels);
    </code>
    where "result" is a defined variable of type float, I call the other function this way as well in line 36. when I compile The program though I get the error: parse error before ')'. I have tried everything, but to be honest I don't understand what parse or parsing is, let alone a parse error. I'll insert the function definition.
    <code>
    //funtion #1
    float farenhiet_(float cels)
    {
    float result;
    result = (1.8 * cels) + 32;
    return result;
    </code>
    If you need the whole source I'll cut and paste that as well just let me know. Any help would be very appreciated. Thanks

  2. #2
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    OK, post the code, execept use the code tags with [], not <>

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Perhaps you have to use 32.0 instead of 32, since you use floats.
    Not sure what a parse error is though...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    9

    corrected tags

    sorry about the first post. w/ wrong code tags.

    Code:
    29.     result = farenhiet_( float cels );
    This is the definition:
    Code:
    //funtion #1
      float farenhiet_(float cels)
      {
      float result;
      result = (1.8 * cels) + 32;
      return result;

  5. #5
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Post all your code and I'm sure that's a typo where you missed the '}' at the end of your function. Oh wait, no it's not. Probably your problem

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    9

    whole source

    Code:
    #include <iostream>
    #include <stdlib.h>
    //function prototypes
    float celsius_(float faren);
    float farenhiet_(float cels);
    void show_menu();
    int main(int argc, char *argv[])
    {
     //declared variables
     float celsius_, farenhiet_, result, result1;
     celsius_ = 0.0;
     farenhiet_ = 0.0;
     //declared variables
     int answer_, pass_;
     answer_ = 0;
     pass_ = 0; 
     
     cout << "This program converts celsius to farenhiet and vice versa. " << endl;
     cout << "Would you like to continue? 0 for No, 1 for Yes."<<endl;
     cin>>pass_;
     while (pass_ > 0)//beginning of while loop
     {                  //with if statements inside
     show_menu();       //first function called   
     cin>>answer_;
        if (answer_ == 1)
     {
        cout << "Enter the degree celsius that you want to convert to farenhiet: "<<endl;
        cin>>celsius_;
        result = farenhiet_( float cels );
        cout << "The answer is: " << result << endl;
     }  
        else if (answer_ == 2)
     {
        cout << "Enter the degree farenhiet that you want to convert to celsius: "<<endl;
        cin>>farenhiet_; 
        result1 = celsius_( float faren );
        cout << "The result is: " << result1 << endl;
        }
      }    
      system("PAUSE");	
      return 0;
      }
      
      //funtion #1
      float farenhiet_(float cels)
      {
      float result;
      result = (1.8 * cels) + 32;
      return result;
      }
      //funtion #2
      float celsius_(float faren)
      {
      float result;
      result = .55 * (faren - 32);
      return result;
      }
      //Function #3
      void show_menu()
      {
      cout << "Enter a number."<<endl;
      cout << "1. Celsius to Farenhiet."<<endl;
      cout << "2. Farenhiet to Celsius."<<endl;
      }

  7. #7
    Registered User
    Join Date
    Aug 2002
    Posts
    9
    I tried taking the "float" out of the call...ended up with more errors.

  8. #8
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Code:
    float celsius_(float faren)
      {
      float result;
      result = .55 * (faren - 32);
      return result;
      }
    Try using:
    Code:
    result = 0.55*(faren-32);

  9. #9
    Registered User
    Join Date
    Aug 2002
    Posts
    9
    The reason for the underscores is because I was changing the code around so much that it began getting very confusing trying to follow the variables around so I put underscores after the variables in the main and in my function prototypes. It may seem weird to you but it was less confusing to me.

  10. #10
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Well you can still change it's name. how about celsius1_

  11. #11
    Registered User
    Join Date
    Aug 2002
    Posts
    9
    I changed the varibles: celsius_ , farenhiet_ to celsius, farenhiet.
    deleted the underscores and followed them in the main and corrected them too. compiled and the parse error remained..
    Do you think it might have to do with my Compiler it's a Bloodshed C++ compiler. a free one.

  12. #12
    Registered User
    Join Date
    Aug 2002
    Posts
    9
    I changed the variable names like you said and put 0.55*(faren -32).
    Code:
    #include <iostream>
    #include <stdlib.h>
    //function prototypes
    float celsius1(float faren);
    float farenhiet1(float cels);
    void show_menu();
    int main(int argc, char *argv[])
    {
     //declared variables
     float celsius, farenhiet, result, result1;
     celsius = 0.0;
     farenhiet = 0.0;
     //declared variables
     int answer, pass;
     answer = 0;
     pass = 0; 
     
     cout << "This program converts celsius to farenhiet and vice versa. " << endl;
     cout << "Would you like to continue? 0 for No, 1 for Yes."<<endl;
     cin>>pass;
     while (pass > 0)//beginning of while loop
     {                  //with if statements inside
     show_menu();       //first function called   
     cin>>answer;
        if (answer == 1)
     {
        cout << "Enter the degree celsius that you want to convert to farenhiet: "<<endl;
        cin>>celsius;
        result = farenhiet1( float cels );
        cout << "The answer is: " << result << endl;
     }  
        else if (answer == 2)
     {
        cout << "Enter the degree farenhiet that you want to convert to celsius: "<<endl;
        cin>>farenhiet; 
        result1 = celsius1( float faren );
        cout << "The result is: " << result1 << endl;
        }
      }    
      system("PAUSE");	
      return 0;
      }
      
      //funtion #1
      float farenhiet1(float cels)
      {
      float result;
      result = (1.8 * cels) + 32;
      return result;
      }
      //funtion #2
      float celsius1(float faren)
      {
      float result;
      result = 0.55 * (faren - 32);
      return result;
      }
      //Function #3
      void show_menu()
      {
      cout << "Enter a number."<<endl;
      cout << "1. Celsius to Farenhiet."<<endl;
      cout << "2. Farenhiet to Celsius."<<endl;
      }

  13. #13
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Chizzlah
    Do you think it might have to do with my Compiler.
    no
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 03:29 AM
  2. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 07:32 PM
  3. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 03:49 PM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 10:11 PM

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