Solved

Syntax Error

Posted on 2011-03-20
6
329 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
Comment Utility
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
Comment Utility
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
Comment Utility
Oh, it's 5/9 not 50/9.
And you don't need the () on the return.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 32

Accepted Solution

by:
phoffric earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks to every body.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now