c++ - Function prototype difficulties -


i having difficulties in getting program working properly. part of project having difficulties with, need create function validates 2 different numbers input user. in whenever run program 2 errors going on.

one input first read me inputting 0 (even though didn't)

and second treats runs first input through second inputs validation test

function prototypes:

int validate(int , int); 

main:

do {            //display menu     displaymenu();     cin >> choice;      validate(choice, months);      // process user's choice     if (choice != quit_choice)     {         // number of months         cout << over3 << "for how many months? ";         cin >> months;          validate(choice, months); } 

and function prototype in question:

int validate(int choice, int months) { while (choice < 1 || choice > 4) {     cout << over3 << choice << " not between 1 , 4! try again: ";       cin >> choice; }  while (months < 1 || months > 12) {     cout << over3 << months << " not between 1 , 12! try again: ";      cin >> months; }  } 

since both of them independent of each other, need separate 2 functions purpose : validatechoice consists of first while loop , validatemonths consists of second while loop.

if want single function need pass appropriate parameter

int validate(int value, int lowlimit, int highlimit) {     while(value < lowlimit || value > highlimit)     {         //print error message here         cin>> value;     }     return value; } 

in main,

cin >> choice; choice = validate(choice, 1, 4); 

similarly months.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -