GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Apr-2008, 16:55
Psionic_Dillon Psionic_Dillon is offline
New Member
 
Join Date: Apr 2008
Posts: 2
Psionic_Dillon is on a distinguished road
Exclamation

error: expected unqualified-id before "if"


here is the source code:

CPP / C++ / C Code:
//
//  Program to convert temperature from Celsius degree 
//  units into Fahrenheit degree units and also to loop so that the window 
//  stays up and the user can repeat with another conversion:
//  Fahrenheit = Celsius  *  (212-32)/100+32
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std

;int main(int nNumberofArgs, char*  pszArgs[])
;if Fahrenheit = factor * celsius/100 + 32 // Here is the line with the error
{   
	//enter the temerature in Celsius
	int celsius;
	cout << "This Program Converts temperatures from Celsius to Fahrenheit." << endl << endl;
	;cout << "Please enter the temperature in Celsius:"
	;cin >> celsius

	// calculate conversion factor for Celsius
	// to Fahrenheit
	;int factor;
	factor = 212 - 32;

	// use conversion factor to convert Celsius
	// into Fahrenheit values
	int fahrenheit;
	fahrenheit = factor * celsius/100 + 32;

	// output the results (followed by a NewLine)
	cout << "Fahrenheit value is:";
	cout << fahrenheit << endl;

	// wait until user is ready before terminating program
	// to allow the user to see the program results
	system("PAUSE");
	return 0;
 }

what did I do wrong? oh and im thinking of making it if Fahrenheit = Fahrenheit... etc

EDIT: if I am not going about the repeat properly, could you tell me how i would go about it please?

help is much appreciated,
thanks,
Dillon
  #2  
Old 04-Apr-2008, 17:44
L7Sqr L7Sqr is offline
Awaiting Email Confirmation
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: error: expected unqualified-id before "if"


Just a comment, the C interpreter & compiler system doesnt care about whitespace, but humans usually do. So when you place your semicolons, try to put them at the end of the statement they conclude
CPP / C++ / C Code:
int foo = 42;
int bar = 16;
Rather than
CPP / C++ / C Code:
int foo = 42
;int bar = 16
;
As far as conditionals go, any conditional must be wrapped in parenthesis
CPP / C++ / C Code:
if (conditional) {
   /* code block */
} 
while (conditional) {
   /* code block */
}
do {
   /* code block */
} while (conditional);
Also, the way you have things declared, you will not compile (by rearranging things a bit you can see why
CPP / C++ / C Code:
int main(int nNumberofArgs, char*  pszArgs[]) ; /* <-- notice this */

if (Fahrenheit = factor * celsius/100 + 32) {   
You place a semicolon after the main declaration - you never provide a function body for that call.
One other thing to note about your conditionals, to test for equality you will want to use the == operator instead of teh = (assignment) operator. Compilers usually give a warning about this, but it is a tricky bug to track down.
Try to fix those errors and post back with your progress.
  #3  
Old 04-Apr-2008, 20:02
Psionic_Dillon Psionic_Dillon is offline
New Member
 
Join Date: Apr 2008
Posts: 2
Psionic_Dillon is on a distinguished road

Re: error: expected unqualified-id before "if"


Quote:
Originally Posted by L7Sqr
} while (conditional);[/cpp]Also, the way you have things declared, you will not compile (by rearranging things a bit you can see why
CPP / C++ / C Code:
int main(int nNumberofArgs, char*  pszArgs[]) ; /* <-- notice this */

if (Fahrenheit = factor * celsius/100 + 32) {   
You place a semicolon after the main declaration - you never provide a function body for that call.

What do you suggest I do instead? I've tried everything, and no matter what I do, i still run into some sort of problem. I'm beginning to think that there actually characters that have "unqualified-id" as a type of character and want to know which one to put.

BTW, thanks for the other advice
  #4  
Old 04-Apr-2008, 22:23
L7Sqr L7Sqr is offline
Awaiting Email Confirmation
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: error: expected unqualified-id before "if"


In order to define a function, you need to provide the block that will be executed when the function is called. In C/C++ that block is enclosed in { and }.
So, for example
CPP / C++ / C Code:
int foo (int arg); /* <--  declares the function */

int foo (int arg) {
   /*
    * This is teh function body
    */
   return 0;
} 
As you can see, you need to declare a function (every one except main) so that when the function is called later in the code the proper checks can be made against the return types and arguments passed to it.
What you have put together is a declaration, you need to provide the definition of main. So wrap whatever code you want to execute inside the opening and closing brackets.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:03.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.