antcode
antcode

Reputation: 1

expected function body after function declarator codeblocks

I am trying to code a little program which calculates the price with fees.

There is two error messages :

7 : "Expected function body after function declarator"

9 : Expected identifier or "("

The code is :

#include <stdio.h>
#include <stdlib.h>


int main()

    var float : prix_ht,prix_ttc;

{

    //La taxe vaut 2,6 euros

    //Saisie du prix hors taxes
    printf("Saisir le prix hors taxes");
    scanf("%f",&prix_ht);

    prix_ttc==(prix_ht)+(2.6);

    printf("Le prix ttc est :%f",&prix_ttc);

    return 0;
}

enter image description here

Upvotes: 0

Views: 4389

Answers (2)

Pablo
Pablo

Reputation: 13580

var float : prix_ht,prix_ttc;

is not C code, you declare variables like this:

float prix_ht, prix_ttc;

And you should write this line inside your main function:

#include <stdio.h>
#include <stdlib.h>


int main()
{
    float prix_ht, prix_ttc;

    //La taxe vaut 2,6 euros

    //Saisie du prix hors taxes
    printf("Saisir le prix hors taxes");
    scanf("%f",&prix_ht);

    prix_ttc==(prix_ht)+(2.6);

    printf("Le prix ttc est :%f", prix_ttc);

    return 0;
}

Also note that I fixed your last printf line, you were passing a pointer to float.

And you should check the return value of scanf, you don't know if it was able to read a float and convert it. You should do

if(scanf("%f", &prix_ht) != 1)
{
    fprintf(stderr, "Could not read float for prix_ht\n");
    return 1;
}

And double == is for comparing

    prix_ttc==(prix_ht)+(2.6);

compares the value prix_ttc with prix_ht+2.6, it is not assigning it. You should use only one =:

    prix_ttc=(prix_ht)+(2.6);

Upvotes: 1

Rhythm sharma
Rhythm sharma

Reputation: 118

just put { after int main() and remove { on line no. 5

Upvotes: 0

Related Questions