'else' error without a previous 'if'

-1

I have a problem and I do not know how to solve it.

The program in C that I developed is showing several types of errors and I do not know what could be:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
    int SA, SN;
    int NOME, AUMENTO;
    printf ("NOME");
    scanf ("%f", &NOME);
    if (SA <= 400);
    SN= SA*1.12;
    AUMENTO="15%";
    else
    if (SA <=700);
    SN=SA*1,12;
    AUMENTO= "12%";
    else
    if (SA <=1000);
    SN=SA*1,1
    AUMENTO= "10%";
    else
    if (SA <= 1800);
    SN=SA*1,07;
    AUMENTO= "7%";
    else
    if (SA <=2500)
    SN=SA*1,04;
    AUMENTO= "4%";
    else
    AUMENTO="sem aumento"
    printf ("NOME: ", NOME, ",% de aumento: ", AUMENTO, ",Salario atual", SA, "Novo salário: ",SN);
    System ("PAUSE");

    
asked by anonymous 03.04.2014 / 20:53

3 answers

2

Corrected code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    float SA, SN;
    char NOME[30], AUMENTO[10];
    printf ("NOME");
    gets(NOME);
    printf("Informe SA: ");
    scanf("%f", &SA);
    if (SA <= 400) {
        SN = SA*1.15;
        strcpy(AUMENTO, "15%");
    }
    else
        if (SA <= 700) {
            SN = SA*1.12;
            strcpy(AUMENTO, "12%");
        }
        else
            if (SA <=1000) {
                SN = SA*1.1
                strcpy(AUMENTO, "10%");
            }
            else
                if (SA <= 1800) {
                    SN = SA*1.07;
                    strcpy(AUMENTO, "7%");
                }
                else
                    if (SA <= 2500) {
                        SN = SA*1.04;
                        strcpy(AUMENTO, "4%");
                    }
                    else {
                        SN = SA;
                        strcpy(AUMENTO, "sem aumento");
                    }
    printf ("NOME: %s, %% de aumento: %s, Salario atual: %.2f, Novo salário: %.2f\n", NOME, AUMENTO, SA, SN);
    system ("PAUSE");
    return 0;
}

But note that it could get much simpler, for example:

#include <stdio.h>
#include <stdlib.h>
int main() {
    float SA, SN;
    char NOME[30];
    int AUMENTO;
    printf ("NOME");
    gets(NOME);
    printf("Informe Salário Atual: ");
    scanf("%f", &SA);
    if (SA <= 400)
        AUMENTO = 15;
    else
        if (SA <= 700)
            AUMENTO = 12;
        else
            if (SA <=1000)
                AUMENTO = 10;
            else
                if (SA <= 1800)
                    AUMENTO = 7;
                else
                    if (SA <= 2500)
                        AUMENTO = 4;
                    else
                        AUMENTO = 0;
    SN = SA * (float) (100 + AUMENTO) / 100;
    printf ("NOME: %s, %% de aumento: %d, Salario atual: %.2f, Novo salário: %.2f\n", NOME, AUMENTO, SA, SN);
    system ("PAUSE");
    return 0;
}
    
03.04.2014 / 21:44
2

Your code does not have correct block syntax, it lacks keys to assign sequence of code.

Example:

if (SA <= 400){
  SN= SA*1.12;
  AUMENTO="15%";
}else{
  //continuando seus if...
}

So it gives error saying that your else, elseif has no corresponding

    
03.04.2014 / 21:03
1

At a glance I notice that the code has lots of missing dot-and-comma errors on multiple lines, and in excess on lines with * if * s. Also missing keys in the if blocks.

    
03.04.2014 / 21:23