+ 1
Hey how can one make a program reject certain values eh those above 100.
Am creating a program that takes student marks so i want the program to reject any marks enter below 0 or above 100
2 Respuestas
+ 2
you can use jest like this for c++
int a;
cin>>a;
if(a>=0 && a<=100){
//statement
}else{
cout<< " invalid input";
}
+ 2
For python, try:
import sys
mark = input(“Whats the mark?\n”)
try:
mark = int(mark)
except ValueError:
sys.exit()
if mark <= 100 and mark >= 0:
#Code
else:
#Other code
Hope this helps!