problem with C code conversion

Asked

Viewed 167 times

-2

I’d like to turn that into code C I’ve done everything I’m only having the problem in part "If MEDIA >=6 And FALTAS <=10 So" mostly on the part of And I don’t know how I’m gonna separate the account.

Programa CalculoMedia2 
Var 
N1, N2, MEDIA: Real 
FALTAS: Inteiro 
Início 
Leia N1 
Leia N2 
Leia Faltas 
MEDIA ← (N1+N2)/2 
Se MEDIA >=6 E FALTAS <=10 Então 
 Escreva “Aluno aprovado com média: ”, MEDIA 
 Senão 
 Escreva “Aluno reprovado com média: ”, MEDIA 
Fim Se 
Fim
  • If using && should work. if (MEDIA >= 6 && MISSING <= 10) {...

  • 4

    I seem to be missing some research work...

  • It would be better to change the form of your question. Someone who wanted to reference himself in the future will not understand what it is. You need to formulate a well-defined question.

  • 4

    Matheus, concerning the rollback from @Ciganomorrisonmendez: we can not convert our question into a totally different one. Once explained the problem and obtained at least one response, We should not change the essence of the question because it invalidates the answers given. We should open a new question and link to the original explaining the new situation.

  • Or, in this case, edit the question and add more content.

4 answers

3


You can use the && to represent the expression E, getting:

if (MEDIA >= 6 && FALTAS <= 10)

2

Portugol:

Se MEDIA >=6 E FALTAS <=10 Então 
    Escreva “Aluno aprovado com média: ”, MEDIA 
Senão 
    Escreva “Aluno reprovado com média: ”, MEDIA 
Fim Se

C:

/*Observação: utilizei o nome minúsculo para as variáveis *media* e *faltas* porque uma boa prática de programação é utilizar todas as letras maiúsculas apenas em constantes.*/
if (media >= 6 && faltas <= 10) {
    printf("Aluno aprovado com média: %f", media);
} else {
    printf("Aluno reprovado com média: %f", media);
}

1

To represent the expression E(and) in C, there is the operator &&, thus:

if (MEDIA >=6 && FALTAS <=10)

Already I’m going to advance here, when you need to use OR in C, there is the operator ||, if the expression were "If MEDIA >=6 OR FALTAS <=10 So, "so, then,:

if (MEDIA >=6 || FALTAS <=10)

1

I solved the problem by converting the code to:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
    float N1, N2, MEDIA;
    float FALTAS;
    printf ("Primeira nota: ");
    scanf ("%f", &N1);
    printf ("Segunda nota: ");
    scanf ("%f", &N2);
    printf ("numero de faltas: ");
    scanf ("%f", &FALTAS);
    MEDIA= (N1+N2)/2;
    if (MEDIA >=6 && FALTAS <=10)
    printf ("\nAluno aprovado com media: %f\n", MEDIA);
    else
    printf ("\nAluno reprovado com media: %f\n", MEDIA);
    system ("PAUSE");
}
  • If you say "need to use real numbers in the notes and integers when missing" then exchange "float FALTAS;" for "int FALTAS;" and "scanf ("%f", &FALTAS);" for "scanf ("%d", &FALTAS);".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.