Hey how can one make a program reject certain values eh those above 100. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

16th Oct 2018, 4:39 PM
Nelson Mandela
Nelson Mandela - avatar
2 Answers
+ 2
you can use jest like this for c++ int a; cin>>a; if(a>=0 && a<=100){ //statement }else{ cout<< " invalid input"; }
16th Oct 2018, 4:46 PM
estifanos
estifanos - avatar
+ 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!
16th Oct 2018, 5:43 PM
Gavin
Gavin - avatar