Hey what's goin guys?
OK I got a real quick question for you all that has been bothering me. How can I get the EOF (or ctrl-d) to work on my C++ program. I know in C you can use getchar, but I am using integers as input on this program.
Any advice/hints on how to fix this?
CJCode:#include<iostream.h> #include<stdio.h> void print( int min2, int max2, int n=5); //Declaration int main() { // system("clear"); int q=0, j=0, y=0, min=0, middle=0, max=0; cout<< "\n\t-This program prints out the default and middle amount of numbers-"; cout<< "\n\n\tEnter (<ctrl-d> <return>) to quit the program.\n"; cout<< "\n\n\tEnter three numbers with spaces: "; cin>> q >> j >> y; fflush(stdin); while( q != !EOF ) { if( q > j) //Checks for max value { if(q > y) max = q; else max = y; } else { if(j > y) max = j; else max = y; } if( q < j) //Checks for min value { if(q < y) min = q; else min = y; } else { if(j < y) min = j; else min = y; } if ( max == q ) //Uses max & min to find middle { if ( min == y ) middle = j; else middle = y; } if ( max == y ) { if( min == q) middle = j; else middle = q; } else if( max == j) { if ( min == q ) middle = y; else middle = q; } cout<< "\n\tUsing default line-set (5)"; cout<< "\n\tPrint 5 per line...\n"; print(min, max ); //Use print function with default line-set // system("sleep 3"); cout<< "\n\n\tNext line-set..."; cout<< "\n\tUsing line-set " << middle; cout<< "\n\tPrint " << middle << " per line...\n"; print(min, max, middle); //Use print function with middle as line-set cout<< "\n\n\tEnter three numbers with spaces: "; cin>> q >> j >> y; fflush(stdin); } printf("\n\n\tPress enter to exit...\n"); getchar(); return 0; } void print( int min2, int max2, int n) //Definition { int count=0; cout<< "\n\t"; for( int i = min2; i <= max2; i++) { cout<< i << " "; count++; if (count == n) //Checks for new line { cout<< "\n\t"; count=0; } } cout<< "\n"; }



LinkBack URL
About LinkBacks


