| | |
Floating point numbers
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Well, in that case you need to test for '-':
C++ Syntax (Toggle Plain Text)
if (string[0] == '-') cout<<"Negative value"<<endl; else cout<<"Positive value"<<endl;
New members chased away this month: 5
•
•
•
•
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
C++ Syntax (Toggle Plain Text)
float x; cin >> x; if(x < 0) cout << "You entered a negative number\n"; else cout << "You entered a positive number\n"; cout << "The real part: " << int(x) <<"\n"; 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:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
Similar Threads
- Floating point numbers (Assembly)
- Assembly floating point (Assembly)
- Fixed to Floating point conversions (C)
- Floating point numbers (C)
- Dynamic Array, Writing to CSV, Floating Point ?'s (C)
- IEEE Floating-point fromat (C)
Other Threads in the C++ Forum
- Previous Thread: memory
- Next Thread: Borland C++ vr 4.5
Views: 8357 | Replies: 23
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






