Hi everyone, Im new to this forum and taking a C programming course. I am having trouble here validating that the user does not input any negatives or any value or 10. But I can't seem to make it work right.
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
system("clear");
int input;
int choice; //Allow the user to enter Y or N
choice = 0;
do while (choice == 0)
{
printf("Please enter a number between 1 and 10 to convert: \n");
scanf("%d", &input);
printf("--------------------------- \n");
if(input <= 1 || input <= 10)
{
printf("Please enter a number between 1 and 10 \n");\
scanf("%d", &input);
printf("--------------------------- \n");
}
else if(input == 1)
{
printf("The number 1 is I in roman numerals \n");
}
else if(input == 2)
{
printf("The number 2 is II in roman numerals \n");
}
else if(input == 3)
{
printf("The number 3 is III in roman numerals \n");
}
else if(input == 4)
{
printf("The number 4 is IV in roman numerals \n");
}
else if(input == 5)
{
printf("The number 5 is V in roman numerals \n");
}
else if(input == 6)
{
printf("The number 6 is VI in roman numerals \n");
}
else if(input == 7)
{
printf("The number 7 is VII in roman numerals \n");
}
else if(input == 8)
{
printf("The number 8 is VIII in roman numerals \n");
}
else if(input == 9)
{
printf("The number 9 is IX in roman numerals \n");
}
else if(input == 10)
{
printf("The number 10 is X in roman numerals \n");
}
//Ask the user if they want to play again.
printf("Would you like to play again? 1 = Yes, 2 = No \n");
printf("--------------------------- \n");
scanf(" %d", &choice);
if (choice == 1)
{
printf("Please enter a number between 1 and 10 to convert: \n");
scanf("%d", &input);
printf("--------------------------- \n");
if(input <= 1 || input <= 10)
{
printf("Please enter a number between 1 and 10 \n");\
scanf("%d", &input);
printf("--------------------------- \n");
}
if(input == 1)
{
printf("The number 1 is I in roman numerals \n");
}
else if(input == 2)
{
printf("The number 2 is II in roman numerals \n");
}
else if(input == 3)
{
printf("The number 3 is III in roman numerals \n");
}
else if(input == 4)
{
printf("The number 4 is IV in roman numerals \n");
}
else if(input == 5)
{
printf("The number 5 is V in roman numerals \n");
}
else if(input == 6)
{
printf("The number 6 is VI in roman numerals \n");
}
else if(input == 7)
{
printf("The number 7 is VII in roman numerals \n");
}
else if(input == 8)
{
printf("The number 8 is VIII in roman numerals \n");
}
else if(input == 9)
{
printf("The number 9 is IX in roman numerals \n");
}
else if(input == 10)
{
printf("The number 10 is X in roman numerals \n");
}
//Ask the user if they want to play again.
printf("Would you like to play again? 1 = Yes, 2 = No \n");
printf("--------------------------- \n");
scanf(" %d", &choice);
choice = 0;
}
else if (choice == 2)
{
break;
}
}
while (choice == 0);
return 0;
}