LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 584 users online 221763 members 879 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
UXnIHAOnUXbmUXn
I haven't filled out my profile...
Mood: Euphoric
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
4 online / 33 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

C++ HELP!
infinit loop!
Replies: 3Last Post July 12, 2008 6:59pm by HideOrSeek
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( Eric 2009 )


Wealthy Hobo
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 | Days Active: 367
Join to learn more about Eric 2009 United States | Posts: 332 | Points: 4,080
LiveWire Humor
( Eric 2009 )


Wealthy Hobo
Reply
NEVERMIND!!!!

6:54 pm on July 12, 2008 | Joined: July 2006 | Days Active: 367
Join to learn more about Eric 2009 United States | Posts: 332 | Points: 4,080
in loveeex3


Professional
Reply
heehee nerd

-------
Sir Tokes Alot is my LW boyfriend(:

6:55 pm on July 12, 2008 | Joined: Dec. 2007 | Days Active: 216
Join to learn more about in loveeex3 New Jersey, United States | Bisexual Female | Posts: 793 | Points: 2,867
HideOrSeek


Connoisseur
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.
Let's scrape our knees on the playground.


6:59 pm on July 12, 2008 | Joined: Mar. 2008 | Days Active: 213
Join to learn more about HideOrSeek Rwanda | Asexual Male | Posts: 3,756 | Points: 6,191
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