-1
Good night, you guys! I am studying C language by myself and, to train, I am trying to encode a program that reads inputs of metallurgical parameters (alloy, temper and thickness) so that a radius value for bending assay is returned to the user. Well, I was able to encode a piece of code with a loop to evaluate the parameters passed by the user, determining whether they are valid for the fold test or not. So far, I’ve been able to filter the alloy, and I’ve been able to determine whether or not it enters the group of alloys that require bending assay, but I’m unable to filter the temper. The code goes below:
for (cont=0; cont<=3;cont++){ //contador para comparação com as ligas cadastradas
if (liga1==liga[cont]){
for (cont=0; cont<=6;cont++){ //contador para comparação com as têmperas cadastradas
if (strcmp(temp1,temp[cont])==0){
printf ("\nDobramento exigido para a liga %d e têmpera %s, na espessura %.3fmm na Norma ASTM!\n", liga1, temp1, esp1);
if (esp1>=esp[0] && esp1<esp[1]){
printf ("\n\nO raio de dobramento é 'x'!\n");
} else if (esp1>=esp[1] && esp1<esp[2]){
printf ("\n\nO raio de dobramento é 'y'!\n");
} else if (esp1>=esp[2]){
printf ("\n\nO raio de dobramento é 'z'!\n");
}
} else if (strcmp(temp1, temp[cont])!=0){ //AQUI ESTÁ A MINHA DIFICULDADE!!!
if (cont==6)
printf ("\nTêmpera sem dobramento!\n");
}
}
} else if (liga1!=liga[cont]){ /*Se a liga não for igual a nenhuma liga cadastrada, retorna
msg, essa condição é verifica antes da têmpera, se retornar verdadeiro, o programa nem avalia
a têmpera e a espessura*/
if (cont == 3){
printf ("Liga não contemplada com ensaio de dobramento na Norma ASTM!\n\a");
}
}
}
I put the comment "HERE IS MY DIFFICULTY" in the line of the code in which I am having problems. I need this line of code to return "Tempering without bending" to the user only when the tempering is not equal to any previously registered tempering in the temp variable (string vector). It turns out that in the execution of the code, it even returns the message correctly in case of tempering different from those that were registered, but is also showing when the user type a valid temper (appearing the message "Tempering without bending" after the message of "Folding required, etc...")! Can you help me, please?
I do not know if I am using the correct method for such an end (this kind of loop of repetition), so I am open to suggestions and criticism, after all they are welcome in learning!
You are using the same variable for alloy index and tempering index, which is within the loop of the first. Use different variables.
– anonimo