Question #38709

B. Modify the InBetween program so that the user must reenter the second value so it is
guaranteed to be higher than the first entered value. Save the file as InBetween2.cpp.

Expert's answer

#include <stdio.h>


int main () {
int lower, upper;

scanf("%d %d", &lower, &upper);

if ( lower > upper ) {
printf("First number has to be smaller than the second one");
return 0;
}

for (int i = lower + 1; i < upper; i++) {
printf("%d ", i);
}
printf("
");
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS