# Thread: expression must be of integral type in function main()

1. ## expression must be of integral type in function main()

Code:
```//uppgift.cpp
#include <iostream>
using namespace std;
#include <float.h>

int main ()
{
float car, tal1, tal2, tal3;

cout <<"*******************************\n";
cout <<"*Bensinförbruknings-kalkylator*\n";
cout <<"*******************************\n\n";

cout <<"Bekräfta med att trycka Enter\n\n";

cout << "\nInmatning - Antal körda mil : ";
cin >> tal1;

cout << "\nInmatning - Antal tankade liter : ";
cin >> tal2;

cout <<"\nVal av bil\n\n";
cout << "(1)Volvo\n";
cout << "(2)Opel\n";
cout << "(3)Saab\n";
cout << "Välj bil genom att ange en siffra mellan 1-3 : ";
cin >> car;
switch (car)
{
case 1:
cout << "Mil\tBil\tLiter\tFörbrukning\n";
cout << "----\t----\t------\t------------\n";
cout << "" << tal1 << " \tVolvo\t " << tal2
<< "      " << (tal2/tal1) << "\n";
cout <<"\n\n\n*******************************\n";
cout <<"*    BilligaBilar AB 2006     *\n";
cout <<"*   Skapat av Patrik Ljung    *\n";
cout <<"*******************************\n\n";
break;
case 2:
cout << "Mil\tBil\tLiter\tFörbrukning\n";
cout << "----\t----\t------\t------------\n";
cout << "" << tal1 << " \tOpel\t " << tal2
<< "      " << (tal2/tal1) << "\n";
cout <<"\n\n\n*******************************\n";
cout <<"*    BilligaBilar AB 2006     *\n";
cout <<"*   Skapat av Patrik Ljung    *\n";
cout <<"*******************************\n\n";
break;
case 3:
cout << "Mil\tBil\tLiter\tFörbrukning\n";
cout << "----\t----\t------\t------------\n";
cout << "" << tal1 << " \tOpel\t " << tal2
<< "      " << (tal2/tal1) << "\n";
cout <<"\n\n\n*******************************\n";
cout <<"*    BilligaBilar AB 2006     *\n";
cout <<"*   Skapat av Patrik Ljung    *\n";
cout <<"*******************************\n\n";

}
return 0;
}```
ok so this is my code and i cant get the switch function to work (dont mind the langauge of the text its in swedish ) but i cant figure out how to get the switch function to work

thank

2. you can't use a float as an argument in a switch. it has to be an integral type; integral as part of the integer family of types. int, char, long, etc.

3. Din variabel "car" är en flyttals-variabel. Det går inte att använda flyttal i switch-satser.

For those who do not understand Swedish:
The variable "car" is a floating point value. It is not possible to use floating point for switch-statements.

--
Mats

4. ok ty i figured it out now