this is the flowchart I am trying to make [1]: https://i.stack.imgur.com/HCFHu.png
and this is my code look so far
#include <stdio.h>
#include <math.h>
int main()
{
int AA = 5;
char NA = 'K';
step2:
if (NA == 'K')
{
printf("NA= %c" , NA);
printf("AA= %d ", AA);
}
else if (AA < 3)
{
(NA = 'B');
printf("NA= %c", NA);
printf("AA= %d", AA);
}
else if (AA < 4)
{
(NA = 'C');
printf("NA= %c", NA);
printf("AA= %d", AA);
}
else
{
printf("input value of NA =");
scanf("%c", &NA);
printf("input value of AA =");
scanf("%d", &AA);
};
goto step2;
return 0;
}
I am trying to make the code after step 6 is false revert back to step 2 until the conditional turns out true help me out here friend!
CodePudding user response:
You should definitely use a loop :
// 1 : initialise na and aa
// 2 : loop while na is not K
while (na != ´K’) {
// 5 : Check aa
If (aa < 3) {
// 7
// 10
} else {
// 4 : test
If () {
// 8
// 9
} else {
// 6 : test aa
… continue with the others test/print statements
}
}
}
// 3 : print aa,na
CodePudding user response:
I decided to write my own solution to this problem, I hope it will help you:
#include <stdio.h>
int main(void) {
char na = 'X';
int aa = 5;
if (na == 'K') {
printf("aa = %d\nna = %c", aa, na);
return 0;
}
if (aa < 3) {
na = 'B';
printf("aa = %d\nna = %c", aa, na);
return 0;
}
if (aa < 4) {
na = 'C';
printf("aa = %d\nna = %c", aa, na);
return 0;
}
/* input */
printf("aa = ");
scanf("%d", &aa);
printf("na = ");
scanf("%u", &na);
printf("\n");
return 0;
}