Ali Ahmad Ali Ahmad - 4 months ago 54
C++ Question

Type Name not allowed/unexpected

I am getting an error I do not understand, mind you i'm new to coding so this may be a simple error.

#include <iostream>

using namespace std;

int main()

//Initialise Fahrenheit
float Fahrenheit = 95.0f;

//Initialise Celcius
double Celcius = float (Fahrenheit - 32)*0.5556;

cout << float Fahrenheit << "F is equal to" << double Celcius << "C" << endl;


return 0;

Very simply, I am trying to write a program which outputs a value of Celsius for a value of Fahrenheit and i'm getting the following errors on line 14

cout << float Fahrenheit << "F is equal to" << double Celcius << "C" << endl;

  • type name is not allowed

  • expected a ;

  • type double unexpected

These errors don't make sense to me in context with that line of code, perhaps I have made an error somewhere else?


You want to write

cout << Fahrenheit << " F is equal to " << Celcius << " C" << endl;

You can't add type names when using variables. Once you define a variable you just use it by its name.

Btw, casting float to float is superflous. And I fail to see the need to mix doubles and floats. Just use double over float unless you have benchmarks to prove you need the smaller type.