I am writing a program to calculate cosines and I should read the user input for angles given in degree (°) or radians (r). If the angle were to be given in degrees, it should be converted into radians (hence I used the if-else statement). However, when I compare char with == and single quote I get the following warning:
warning: multi-character character constant [-Wmultichar]
if((unit != '°') && (unit != 'r'))
This is my full code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
// Prototype
void calc_cos(double, char);
int main (void)
{
double angle;
char unit;
printf("PLease give an angle and its unit in degrees (°) or radians (r) for cosinus calculation\n");
if((unit != '°') && (unit != 'r'))
{
printf("ERROR. Unit is not in '°' or 'r'. Aborting...\n");
return 0;
}
else
{
scanf("%lf %c", &angle, &unit);
calc_cos(angle, unit);
}
return 0;
}
void calc_cos(double angle, char unit)
{
double results=0;
if(unit == '°')
{
angle = angle*M_PI/180;
}
else if(unit == 'r')
{
angle = angle;
}
results = cos(angle);
printf("cos(%lf rad) = %lf\n", angle, results);
}