Floating point numbers

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Floating point numbers

 
0
  #21
Jan 1st, 2005
>if ( string[n] < 0 )
This test is wrong because a printable character will not be less than 0. What are you trying to do to make the code "more powerful"?
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 12
Reputation: happyHour is an unknown quantity at this point 
Solved Threads: 0
happyHour happyHour is offline Offline
Newbie Poster

Re: Floating point numbers

 
0
  #22
Jan 1st, 2005
basically if a user enteres a - followed by the numbers then the statment will look for the sign and says that the sign is a -.

if its not a minus then the number enetered must be a plus
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,867
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Floating point numbers

 
0
  #23
Jan 1st, 2005
Well, in that case you need to test for '-':
  1. if (string[0] == '-')
  2. cout<<"Negative value"<<endl;
  3. else
  4. cout<<"Positive value"<<endl;
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Floating point numbers

 
0
  #24
Jan 1st, 2005
basically if a user enteres a - followed by the numbers then the statment will look for the sign and says that the sign is a -.

if its not a minus then the number enetered must be a plus
so let the user enter a number!!!!

  1. float x;
  2.  
  3. cin >> x;
  4.  
  5. if(x < 0)
  6. cout << "You entered a negative number\n";
  7. else
  8. cout << "You entered a positive number\n";
  9.  
  10. cout << "The real part: " << int(x) <<"\n";
  11. cout << "The fractional part: " << float(x - int(x)) << "\n";
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 8357 | Replies: 23
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC