Solved

Syntax Error

Posted on 2011-03-20
6
334 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 27

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

696 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