Validate the correct month in C -
I am working in this program which is very easy, but I'm having trouble validating the input user, I do not know how the user receives the right output program says that the date of last oil change (month and year) will be found. Verify the input and when the input is incorrect then the user enter the correct value. I have this until now, and I do not know what I have achieved so far is correct:
#include Month & gt; month & lt; = 12) {printf ("month:% i \ n", month); } Else {printf ("Please enter a number between 1-12. \ N"); } Return (0); }
Instead try to do this:
Int main (zero) {int month, year; // Enter the date of last oil change and validate the correct month value printf ("Enter the date of final oil change, month (1-12):"); // To add a place before% i to ignore the whitespace. Scanf ("% i", and month); While (Months <1 || Month & gt; 12) {printf ("Please enter between digits 1-12. \ N"); Scanf ("% i", and month); } Printf ("month:% i \ n", month); Return (0); }
In this way the program keeps asking the user for a price until no one is correctly entered.
Comments
Post a Comment