this program not work

I try to make program the user selects the first number and last number

so show the evens numbers between the first number and the last number that user is selects

the code:
i use while loop to make the program and i sorry

thats the code:

# include <iostream>
using namespace std ;
int main ()
{
double fri=0 , num=1 , last=0 ;

cout<<"Enter the frist number"<<endl ;
cin>> fri ;
cout<<"Enter the last number"<<endl ;
cin>> last ;
while ((fri>num) && (last <num) ){
cout<< num ;
num +2;



}


system("PAUSE" ) ;
return 0 ;
}



thanks and i wait Correct my mistakes


This would work fine except for two things. If the variable fri's value was an odd number it would print out all of the odd numbers between fri and last, or if fri's value was a decimal it would print out numbers with decimals. The other problem is that you have no exception handling. If the user entered a letter instead of a number for some reason, the program would crash.

Two less important things are that you don't need those parenthesis around fri>num or last<num, and first is spelled F-I-R-S-T. I'm assuming you're not a native speaker, but I might as well tell you, I guess.

EDIT: http://www.cplusplus.com/doc/tutorial/exceptions/ for help with exception handling.

EDIT2: Also, why are initializing fri and last with values? You're getting input for them anyways.
Last edited on
Why declare double
double fri=0 , num=1 , last=0 ;
when you are looking for evens/odds number?

another thing is that why not give fri a decent name? like first?
much easier to read .
Last edited on
Topic archived. No new replies allowed.