I was working on a class project and I wanted to do a little bit extra and make validation on my data. The problem seems to happen at num1 = num1Input
(and num2 = num2Input
) where it is getting the location (I assume) instead of the actual input value
int main(void) {
//variables
char num1input[10];
char num2input[10];
int length, i;
int num1 = 0;
int num2 = 0;
int countErrors1 = 0;
int countErrors2 = 0;
bool correct1 = false;
bool correct2 = false;
//--end of variable declarations--//
do {
printf("Please enter a number: ");
scanf("%s", num1input);
length = strlen(num1input);
for (i = 0; i < length; i++) {
if (!isdigit(num1input[i])) {
countErrors1++;
}
}
if (countErrors1 > 0) {
printf("Input is not a number \n");
} else {
correct1 = true;
}
} while (correct1 == false);
num1 = num1input;
do {
printf("Please enter second number: ");
scanf("%s", num2input);
length = strlen(num2input);
for (i = 0; i < length; i++) {
if (!isdigit(num2input[i])) {
countErrors2++;
}
}
if (countErrors2 > 0) {
printf("Input is not a number \n");
} else {
correct2 = true;
}
} while (correct2 == false);
num2 = (int)num2input;
printf("%d %d \n", num1, num2);
int addition = num1 + num2;
int substraction = num1 - num2;
int multiplication = num1 * num2;
float division = num1 / num2;
printf("Addition: %d Subtraction: %d Multiplication: %d Division: %.1e", addition, substraction, multiplication, division);
getch();
}