Solved

Syntax Error

Posted on 2011-03-20
6
332 Views
Last Modified: 2012-05-11
Hi guys: Can any one please tell me why it gives syntax error on that line ? Thanks.
      celsustempValue = calcSensus(getFahrcalcvalue);

--------------------------------------------

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
      double getFahrcalcvalue = 0.00;
      double celsustempValue = 0.00;
      double calcFahr()
            {
                        double FarTemp
                        cout << "Enter Fahrenheit temperature==>";
                        cin >> FarTemp;
                        return(FarTemp);
                  }
      double calcSensus(double CencTemp)
            {
                        double FarTempValue = 0.00;
                        FarTempValue = CencTemp;
                        CencTemp = 50 / 9.0 * (FarTempValue -32.0);
                        return(CencTemp);
                  }

      getFahrcalcvalue = calcFahr();
      celsustempValue = calcSensus(getFahrcalcvalue);
      cout << "Celsius temperature==>" << celsustempValue << endl;
      system("pause");
      return 0;
}  
0
Comment
Question by:mustish1
6 Comments
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 200 total points
ID: 35177880
Because it can't see your functions since you defined them in the wrong place. You need to define the other functions outside the main function, not in it. Like this.
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

      double calcFahr()
            {
                        double FarTemp
                        cout << "Enter Fahrenheit temperature==>";
                        cin >> FarTemp;
                        return(FarTemp);
                  }
      double calcSensus(double CencTemp)
            {
                        double FarTempValue = 0.00;
                        FarTempValue = CencTemp;
                        CencTemp = 50 / 9.0 * (FarTempValue -32.0);
                        return(CencTemp);
                  }

int main()
{
      double getFahrcalcvalue = 0.00;
      double celsustempValue = 0.00;

      getFahrcalcvalue = calcFahr();
      celsustempValue = calcSensus(getFahrcalcvalue); 
      cout << "Celsius temperature==>" << celsustempValue << endl;
      system("pause");
      return 0;
}  

Open in new window


There may be some other issues, but that's the big one.
0
 
LVL 26

Assisted Solution

by:dpearson
dpearson earned 100 total points
ID: 35177883
Not sure why the error seems to be coming later but it appears you're missing a semi colon here:

      double calcFahr()
            {
                        double FarTemp    <=== missing ;
                        cout << "Enter Fahrenheit temperature==>";

Depending on your compiler it also may not love the nested functions and might require them to be moved outside of main.  But if that's a problem it be a pretty clear error.

Doug
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35177885
Oh, it's 5/9 not 50/9.
And you don't need the () on the return.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 32

Accepted Solution

by:
phoffric earned 200 total points
ID: 35177889
Try placing the two functions in main() just above main. This compiles:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

double calcFahr()
{
   double FarTemp;
   cout << "Enter Fahrenheit temperature==>";
   cin >> FarTemp;
   return(FarTemp);
}

double calcSensus(double CencTemp)
{
   double FarTempValue = 0.00;
   FarTempValue = CencTemp;
   CencTemp = 50 / 9.0 * (FarTempValue -32.0);
   return(CencTemp);
}

int main()
{
   double getFahrcalcvalue = 0.00;
   double celsustempValue = 0.00;


   getFahrcalcvalue = calcFahr();
   celsustempValue = calcSensus(getFahrcalcvalue); 
   cout << "Celsius temperature==>" << celsustempValue << endl;
   // system("pause");
   return 0;
}

Open in new window

0
 
LVL 32

Expert Comment

by:phoffric
ID: 35177892
Factor of 10 off:
CencTemp = 50 / 9.0 * (FarTempValue -32.0);

Open in new window

Try:
CencTemp = 5/ 9.0 * (FarTempValue -32.0);

Open in new window

0
 

Author Closing Comment

by:mustish1
ID: 35177919
Thanks to every body.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question