cfunctionif-statementmethods

error compiling in c user input


I have to write a program that asks the user if they are male or female, there birthday (mm dd yyyy) and then the date. and then calculates there age for an insurance thing that is meant for an if else loop to tell the user what price they will be paying. here is my code:

#include<stdio.h>
#include<conio.h>


char* calculateAge(int month, int day, int year, int birthmonth, int birthday, int      birthyear, char gender)
{
    int temp;
    temp = (year - birthyear);
    if (temp >= 33 && <= 62 && gender == 'm' || temp >= 30 && <= 62 && gender == 'f') {
        return "The rate class is: Best rate  - $40.00 per day or $200.00 per week.";
    } else if (temp >= 25 && <= 29 && gender == 'f') {
         return "The rate class is: Risk rate 1 - Best rate plus $10.00 per day or best     rate plus $55.00 per week.";
    } else if (temp >= 25 && <= 32 && gender == 'm') {
            return "The rate class is: Risk rate 1 - Risk rate 1 plus $7.00 per day or risk rate 1     plus $30.00 per week.";
        } else if (temp >= 66 && gender == 'm' || temp >= 63 && gender == 'f') {
             return "The rate class is: Best rate plus $2.00 for each year over age 66 (male) or 63    (female), per day or best rate plus $5.00 for each year over age 66 (male) or 63 (female), per     week."
    } else {
        return "Sorry, the renter is not 25 years of age or older.";
    }
}

void main() {
int month, day, year, birthmonth, birthday, birthyear;
char gender;
printf("\nWelcome to the car renter’s rate finder. " );
printf("\nPlease enter today's date (mm dd yyyy): ");
scanf("%d%d%d",&month, &day, &year);
printf("\nPlease enter the renter’s gender (m/f):" );
scanf("%c", &gender);
printf("\nPlease enter the renter’s date of birth (mm dd yyyy):");
scanf("%d%d%d", &birthmonth, &birthday, &birthyear);
printf("\n Thank you.");
printf("%s", calculateAge(month, day, year, birthmonth, birthday, birthyear, gender));
return 0;
}

i keep getting these errors, saying: line 14: error: expected expression before '<=' token line 16: same line 18: same line 22: error: expected ';' before '}' token

I dont understand these errors, can someone please help me get this programming working? here is the output it should have:

Welcome to the car renter’s rate finder.

Please enter today’s date (mm dd yyyy): 1 23 2008

Please enter the renter’s gender (m/f): m

Please enter the renter’s date of birth (mm dd yyyy): 6 9 1983

Thank you.

Sorry, the renter is not 25 years of age or older.

Welcome to the car renter’s rate finder.

Please enter today’s date (mm dd yyyy): 1 23 2008

Please enter the renter’s gender (m/f): f

Please enter the renter’s date of birth (mm dd yyyy): 2 23 1980

Thank you.

The female renter is 27 years old.

The rate class is: Risk rate 1 - $50.00 per day or $255.00 per week.

Solution

  • When the compiler produces error messages, the most reliable method is to start with the first error message produced. (Sometimes messages may be produced out of order; in that case, start with the one that refers to the lowest line number in your code.)

    If you have a syntax error, the compiler can have difficulty figuring out what you meant. It will often make a guess about what you should have written, but that guess can be wrong. Compilers are sometimes particularly bad at guessing in the presence of missing semicolons.

    Judging by the error messages you got, you're probably using gcc. When I compile your code, the first message I get is:

    c.c: In function ‘calculateAge’:
    c.c:9:23: error: expected expression before ‘<=’ token
    

    Line 9 is:

    if (temp >= 33 && <= 62 && gender == 'm' || temp >= 30 && <= 62 && gender == 'f') {
    

    and column 23 is the first <= operator.

    As it happens, this particular message tells you exactly what the problem is (you need an expression before the <=), but in cases where the message itself is unclear, treat it as an indication that there's something wrong at the place where it's pointing, or perhaps slightly before it (say, on the previous line).

    Fix that error, recompile, and do the same thing with the first error reported on the new version of the file.

    As you understand the language and your compiler better, you should be able to figure out what it's doing and correct multiple errors at once. But for now, fixing one error at a time is a good approach.

    Some other notes on your code:

    Delete this line:

    #include<conio.h>
    

    It's non-portable, and you're not using anything from <conio.h> anyway.

    void main() is wrong; it should be int main(void).