Most of this works correctly, however, i noticed if i try adding a negative integer, this happens:
The correct output line was: Please enter two integers: negative one + three = two Your program printed this line: Please enter two integers:negativethree = two
The ifs after my "printf negative" if statement arent printing for some reason?
#include <stdio.h>
int main(void) {
int numOne;
int numTwo;
printf("Please enter two integers:");
scanf("%d%d", &numOne, &numTwo);
if (numOne >= -10 && numOne < 0) {
printf("negative");
}
if (numOne == 0) {
printf("zero + ");
}
if (numOne == 1) {
printf("one + ");
}
if (numOne == 2) {
printf("two + ");
}
if (numOne == 3) {
printf("three + ");
}
if (numOne == 4) {
printf("four + ");
}
if (numOne == 5) {
printf("five + ");
}
if (numOne == 6) {
printf("six + ");
}
if (numOne == 7) {
printf("seven + ");
}
if (numOne == 8) {
printf("eight + ");
}
if (numOne == 9) {
printf("nine + ");
}
if (numOne == 10) {
printf("ten + ");
} else if (numOne > 10 || numOne < -10) {
printf("%d + ", numOne);
}
if (numTwo >= -10 && numTwo < 0) {
printf("negative");
}
if (numTwo == 0) {
printf("zero");
}
if (numTwo == 1) {
printf("one");
}
if (numTwo == 2) {
printf("two");
}
if (numTwo == 3) {
printf("three");
}
if (numTwo == 4) {
printf("four");
}
if (numTwo == 5) {
printf("five");
}
if (numTwo == 6) {
printf("six");
}
if (numTwo == 7) {
printf("seven");
}
if (numTwo == 8) {
printf("eight");
}
if (numTwo == 9) {
printf("nine");
}
if (numTwo == 10) {
printf("ten");
} else if (numTwo > 10 || numTwo < -10) {
printf("%d = ", numTwo);
}
int total = numOne + numTwo;
if (total >= -10 && total < 0) {
printf(" = negative");
}
if (total == 0) {
printf(" = zero\n");
}
if (total == 1) {
printf(" = one\n");
}
if (total == 2) {
printf(" = two\n");
}
if (total == 3) {
printf(" = three\n");
}
if (total == 4) {
printf(" = four\n");
}
if (total == 5) {
printf(" = five\n");
}
if (total == 6) {
printf(" = six\n");
}
if (total == 7) {
printf(" = seven\n");
}
if (total == 8) {
printf(" = eight\n");
}
if (total == 9) {
printf(" = nine\n");
}
if (total == 10) {
printf(" = ten\n");
} else if (total > 10 || total < -10) {
printf(" = %d\n", total);
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire