c++

Classified in Technology

Written at on English with a size of 1.25 KB.

a) Write a function to convert a numerical grade to a letter:

0.0 ≤ X < 5.0 è D

5.0 ≤ X < 7.0 è C

7.0 ≤ X < 9.0 è B

9.0 ≤ X ≤ 10.0 è A

The function receives as argument a real number and returns its equivalent code.

b) Write a program to convert a numerical mark to its equivalent literal qualification. The program checks if the marks are outside the range 0-10.

#include<stdio.H>

//function prototype

char grade(float);

char grade(float x)

{char ch;

if (x>=0.0 && x<5.0)

ch= 'D';

if (x>=5.0 && x<7.0)

ch= 'C';

if (x>=7.0 && x<9.0)

ch= 'B';

if (x>=9.0 && x<=10.0)

ch= 'A';

return(ch);}

int main()

{float gr;

do{printf("introduce your grade \n");

scanf("%f",&gr);}while (gr<0.0 || gr>10.0);

printf ("Your grade is a %c",grade(gr) );}


Entradas relacionadas: