LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 360 users online 179079 members 475 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Video | Dictionary | News | FAQ
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
3 online / 26 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

C++ HELP!
infinit loop!
Replies: 3Last Post July 12 6:59pm by HideOrSeek
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 | 269 Days Active
Join to learn more about Eric 2009 United States | 273 Posts | 3038 Points
( Eric 2009 )


Executive
Reply
NEVERMIND!!!!

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


Dairy Product Addict
Reply
heehee nerd

-------
talking to a rich skank filled
up like a sperm bankk!

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


Dairy Product Addict
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 | 55 Days Active
Join to learn more about HideOrSeek Venezuela | Label Free Male | 1289 Posts | 1943 Points
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic