inherit
27278
0
Aug 3, 2024 9:13:18 GMT -8
Josh
Apple iManiac / eBay Addict
12,347
July 2004
jwd41190
|
Post by Josh on Sept 2, 2011 19:53:27 GMT -8
void run2(){ float storage [50]; for(int i=0; i<=9; i++){ storage[i] = (i/10.0f + 1); //cout << storage[i] << " "; //if used it will output all 10 numbers } }
It outputs all 10 numbers but the first number is just 1 instead of 1.0....
It prints 1, 1.1, 1.2, 1.3, and so on...but how can I get the first one to print 1.0...thanks
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Sept 3, 2011 9:54:37 GMT -8
You need to use the setprecision method with the fixed flag.
#include <iostream> #include <iomanip>
using namespace std;
int main() { float storage [50]; for(int i=0; i<=9; i++){ storage = (i/10.0f + 1); cout << setprecision(2) << fixed; cout << storage << " "; } return 0; }
|
|
inherit
27278
0
Aug 3, 2024 9:13:18 GMT -8
Josh
Apple iManiac / eBay Addict
12,347
July 2004
jwd41190
|
Post by Josh on Sept 3, 2011 18:40:23 GMT -8
You need to use the setprecision method with the fixed flag. #include <iostream> #include <iomanip>
using namespace std;
int main() { float storage [50]; for(int i=0; i<=9; i++){ storage = (i/10.0f + 1); cout << setprecision(2) << fixed; cout << storage << " "; } return 0; }ok thanks man, I was thinking about that iomanip and setprecision just forgot about the fixed thing.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Sept 4, 2011 20:54:29 GMT -8
Glad to help. What classes are you taking now?
|
|
inherit
27278
0
Aug 3, 2024 9:13:18 GMT -8
Josh
Apple iManiac / eBay Addict
12,347
July 2004
jwd41190
|
Post by Josh on Sept 5, 2011 6:32:10 GMT -8
Glad to help. What classes are you taking now? Just sent you a pm
|
|