Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is in Visual Studio Code

A qdriver file with this code

#include <stdio.h>  // printf

void temperature_convertor(int fahrenheit);

int main(void)
{
	// test case 1
	temperature_convertor(0);
	printf("\n");

	// test case 2
	temperature_convertor(20);
	printf("\n");

	// test case 3
	temperature_convertor(300);
	printf("\n");

	// test case 4
	temperature_convertor(-20);
	printf("\n");

	// test case 5
	temperature_convertor(137);
	printf("\n");

	// test case 6
	temperature_convertor(-300);
	printf("\n");

	return 0;
}


linked to a q.c file with this code

#include <stdio.h>  // printf
void temperature_convertor(int fahrenheit); 
{
	int C = (int fahrenheit - 32);
    int Ce = int C * 5;
    int celsius = (int Ce/9);
    int kelvin = (int celsius + 273.15);
}


But it comes out an error as per the title, expected identifier or ‘(’ before ‘{’ token in the third line of the second block of code. Any help?

What I have tried:

I'm stuck to be honest, I'm a beginner at this.
Posted
Updated 25-Sep-21 6:51am
Comments
Peter_in_2780 25-Sep-21 1:13am    
Have a look at what is before the { (i.e. on the previous line). Hint: There's one character that shouldn't be there, but you need to figure it out so you can learn to read your code (and other peoples').
The error message isn't particularly helpful, but it does point at the right place.

A Semicolon at the end of a function signature indicates a Forward declaration[^] - a way of providing the signature of a method before the body has been defined so that it can be called before the body has been declared.
That allows this to work:
C
void foo()
   {
   bar();
   }
void bar()
   {
   foo();
   }
Without forward declarations, there is no way to write that code that means that the system can check the signatures of both functions!
C
void foo();
void bar();
...
void foo()
   {
   bar();
   }
void bar()
   {
   foo();
   }
Now the compiler can meet the body of both functions in either order.
C is an old language; modern languages like C# do not have this restriction!

So when you look at your code:
C
void temperature_convertor(int fahrenheit); 
{
	int C = (int fahrenheit - 32);
    int Ce = int C * 5;
    int celsius = (int Ce/9);
    int kelvin = (int celsius + 273.15);
}
The semicolon at the end of the function signature turns it into a forward declaration, and the system doesn't know what to do with the rest of the code as it isn't contained in any function.

But when you have fixed that, your temperature_convertor function body will need changes as well: you don't need to specify variable types every time you use them!
For example:
C
int C = (int fahrenheit - 32);
won't work because you have the type definition int before the use of fahrenheit:
C
int C = fahrenheit - 32;
Will fix that, and so on.
 
Share this answer
 
I would try
C++
#include <stdio.h>  // printf
void temperature_convertor(int fahrenheit);
void temperature_convertor(int fahrenheit)
{
	int C = (int fahrenheit - 32);
    int Ce = int C * 5;
    int celsius = (int Ce/9);
    int kelvin = (int celsius + 273.15);
}

I fear your code have other problems too.
 
Share this answer
 
v2
I would rewrite your converter to look something like this :
C++
double temperature_convertor( int fahrenheit )    // no semicolon should be here 
{
	int temp = 5 * (fahrenheit - 32);
    double kelvin = ( temp / 9.0 ) + 273.15;
    return kelvin;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900