// Zeinalipour-Yazti Demetrios // csyiazti // cs10xx - // Lab Sec#25-#39 // lab5 /* * This program asks the user for two integers. * The user should also specify "even" or "odd". * It then outputs all the specified types of numbers within the range. */ #include using namespace std; /* This function asks the user to input the value: valuename[]. * @return : the selected value */ int getValue(char valuename[]) { /* defining local scope variables*/ int value; cout << "Please type the \"" << valuename << "\" of the range: "; cin >> value; return value; } /* This function asks the user to select the type "odd" or "even" * @return : 1 for odd * 2 for even */ int getType() { /* defining local scope variables*/ int value; /* Getting the value */ while (true) //start while1a { cout << "Please select the type: 1 or 2 (1=odd, 2=even) : "; cin >> value; if (value==1 || value==2) { break; } else { cout << "Error# - You can only select 1 or 2 !" << endl; } } //end while1a return value; } void main() { /* define variables */ int start, end; /* range start and end */ int type; /* defines the type : (1=odd or 2=even) */ /* define functions & procedures*/ int getValue(char valuename[]); /* returns the value given by the user */ int getType(); /* returns the type 1 or 2 (1=odd,2=even)*/ /* make sure that the end range is greater than the start range*/ start = getValue("start"); end = getValue("end"); if (end < start) { cout << "\nSwapping \"start\" with \"end\" ==> start = " << end << " , end = " << start << endl << endl; int temp = end; end = start; start = temp; } /* get the type from the user [1 or 2] (1=odd, 2=even) */ type = getType(); /* print out the result*/ for (int i=start; i<=end ; i++) { if ( (type==2) && (i%2==0) ) { cout << i << endl; } else if ( (type==1) && (i%2!=0) ) { cout << i << endl; } } }