cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Decimal Problem
Decimal Problem
Mar 26, 2011 at 12:05am UTC
Kearney401
(2)
Having a problem with my code... its not showing the decimal point when its outputted? anybody have any of suggestions why this is happens and how I could fix this?
#include<stdlib.h>
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
int main()
{
int hold;
double num;
for (int i=1; i<100; i++)
{
num = 1/i;
cout<<setprecision(9)<<num<<"\n";
num == 0;
}
cin>>hold;
}
Mar 26, 2011 at 12:07am UTC
hanst99
(2869)
1/i is an integer division, and is always 0 unless i is 1. Use 1f/i or 1.0/i or something like that.
Mar 26, 2011 at 12:15am UTC
Kearney401
(2)
Thanks works now :)
Topic archived. No new replies allowed.