Heya, so I've been learning to code in 'C' for three days and I decided to write a very basic calculator program (It's more of an abacus really), its completely functional but it has a few bugs one of them is in the loop function that decides what mathematical process will be applied, basically if in an invalid character is input by the user it should loop back to the start of that section but it doesn't ill post the code below so someone can check it out and feel free to tear it apart and tell me what I could do better or did wrong

:)



#include
#include

int main()
{
//Variables
float num, sum;
char func, select;
int mathFunc;



do{
//Select a number to process
do{
printf("\nType in a number : ");
scanf(" %f", &num);
printf("Is %.0f the correct number? (y/n): ", num);
scanf(" %c", &select);
if (select == 'y'){
break;

} if (select == 'n') {
select = 'n';

}else{
select = 'n';
}
}while(select == 'n');


//Select Basic Math Function

do{
printf("\nWould you like to add , subtract, multiply, or divide? (a/s/m/d): ");
scanf(" %c", &func);
printf("Is %c correct? (y/n): ", func);
scanf(" %c", &select);
if (select == 'y'){
break;
}else {
select = 'n';
}
}while (select == 'n');





/*Selects from avaliable math operations based on user input
and verifys the integer that will be added or subtracted etc*/

do{
if (func=='a'){
printf("\nhow much would you like to add to %.0f?\n", num);
scanf(" %d", &mathFunc);
printf("you would like to add %d, is that correct? (y/n): ", mathFunc);
scanf(" %c", &select);

}else if (func=='s'){
printf("\nhow much would you like to subtract off %.0f?\n", num);
scanf(" %d", &mathFunc);
printf("you would like to subtract %d, is that correct? (y/n): ", mathFunc);
scanf(" %c", &select);

}else if (func=='d'){
printf("\nhow much would you like to divide %.0f by?\n", num);
scanf(" %d", &mathFunc);
printf("you would like to divide by %d, is that correct? (y/n): ", mathFunc);
scanf(" %c", &select);

}else if (func=='m'){
printf("\nhow much would you like to multiply %.0f by?\n", num);
scanf(" %d", &mathFunc);
printf("you would like to multiply by %d, is that correct? (y/n): ", mathFunc);
scanf(" %c", &select);

}else {
select = 'n';
}


if (select == 'y'){
break;
}
if (select == 'n'){
select = 'n';
}
else {
select = 'n';
}

}while (select == 'n');


//Lets do the maths!!!!

if (func == 'a'){
printf("%.0f + %d = %.2f\n\n", num, mathFunc, sum = num + mathFunc);
}else if (func == 's'){
printf("%.0f - %d = %.2f\n\n", num, mathFunc, sum = num - mathFunc);
}else if (func == 'd'){
printf("%.0f / %d = %.2f\n\n", num, mathFunc, sum = num / mathFunc);
}else if (func == 'm'){
printf("%.0f / %d = %.2f\n\n", num, mathFunc, sum = num * mathFunc);
}
printf("would you like to calculate again? (y/n): ");
scanf(" %c", &select);
if (select == 'n'){
break;
}else if (select == 'y'){
continue;
}else {
break;}

}while (select == 'y');





return 0;

}