PeopleGalleryZombiesFrolfProf ReviewsDictionaryBuy/SellForumsMovies

Sign In | Join


  » DormWire / Technical Forums / Programming & Application Development / Viewing Topic

C++ HELP!
infinit loop!
Replies: 3Last Post July 12 6:59pm by HideOrSeek

(+) New Topic   (+) New Poll (+) Add Reply
Single page for this topic Email Print Favorite
( Eric 2009 )


Executive
Reply
#include <iostream>
using namespace std;
const double m_to_k = 1.609;
inline int convert(int mi) {return (mi * m_to_k);}

int main(){

int miles;

do{
cout<<"Input your miles: ";
cin >>miles;
if (miles == 1.609){
cout<<"1 mile." <<endl;
}
else{
cout <<"\nDistance is " << convert(miles) << " km." <<endl;
}
}while(miles > 0) ;
return(0);
}

when i input 1.609 i get an infitine loop that continues until i manually close the program


6:53 pm on July 12, 2008 | Joined July 2006 | 282 Days Active
Join to learn more about Eric 2009 United States | 287 Posts | 3183 Points
( Eric 2009 )


Executive
Reply
NEVERMIND!!!!

6:54 pm on July 12, 2008 | Joined July 2006 | 282 Days Active
Join to learn more about Eric 2009 United States | 287 Posts | 3183 Points
in loveeex3


Dairy Product Addict
Reply
heehee nerd

-------
i am barack obama and i approve this message.

6:55 pm on July 12, 2008 | Joined Dec. 2007 | 144 Days Active
Join to learn more about in loveeex3 New Jersey, United States | Straight Female | 559 Posts | 1977 Points
HideOrSeek


Professional
Reply
"if (miles == 1.609){
cout<<"1 mile." <<endl;
}
else{
cout <<"\nDistance is " << convert(miles) << " km." <<endl;
}
}while(miles > 0) ;
return(0);
} "

What if you get rid of the If, and instead converting in Else, just Convert whatever the user inputs?

Besides, why are you using a loop?
I think you just need to do the procedure once, you could use a loop when asking the user if he'd like to convert a different measure...
Hmn?

-------
Mi-Re-Do-Re-Mi-Fa-Mi.


6:59 pm on July 12, 2008 | Joined Mar. 2008 | 70 Days Active
Join to learn more about HideOrSeek Venezuela | Label Free Male | 1384 Posts | 2178 Points
Single page for this topic Email Print Favorite
(+) New Topic   (+) New Poll (+) Add Reply

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  » DormWire / Technical Forums / Programming & Application Development / Viewing Topic



  © 2008 DormWire | Custom Web Hosting | Terms of Use | Site Map | Contact | FAQ