There is an easy solution for this, use an array of char
:
#include <stdio.h>
#include <string.h>
#include <math.h>
//Funciones para Area
float areftcir(float r); //Area de un circulo
int main(void) {
float ra, res;
char cadena[10]; // Lo suficientemente grande como para aceptar "continuar"
do {
printf("\n\nIntrduzca el valor del radio: ");
scanf("%f", &ra);
res = areftcir(ra);
printf("Respuesta: %f", res);
printf("\n\nIngrese 'continuar' o 'salir': ");
scanf("%s[^\n]", &cadena);
} while (strcmp(cadena, "continuar") == 0);
}
float areftcir(float r) {
float raftc;
raftc = (3.1416) * (r * r);
return raftc;
}
Basically what it does is compare if the content of cadena
is equivalent to "continuar"
.
The biggest problem with this is that it will only work if the user types continuar
in lowercase, without punctuation or anything, and will ignore any other words you enter.
Additionally, something bad can happen if you spend 10 characters.
I have changed your cycle while
with a do { ... } while
to perform the operations of the program at least once.
EDIT :
To make it more comfortable for the user, I have made a small improvement, which is to ignore the (Uppercase or Lowercase) typeface :
First, we add the function prototype:
char *str_tolower(char *ptr);
And we define it in the following way:
char *str_tolower(char *ptr) {
char *test = ptr;
while (ptr && *ptr) {
*ptr = tolower(*ptr); ++ptr;
}
return test;
}
Then we just change the following line:
} while (strcmp(cadena, "continuar") == 0);
By:
} while (strmp(str_tolower(cadena), "continuar") == 0);
And now the user is able to write "continuar"
in any way.