okay, i know i might be boring with my questions but could someone tell me how can i read an array of floats mixed with ints and then print them out same as they were on input...?
typecasting thing again? anyone knows a good book i could use to stop torturing this forum, i got the c++ primer but it aint helpful at all. and i don't wanna hear B from Bjarne...

## All 5 Replies

you noob. you're banned.

just kidding.

but seriously, you cant have a single array of floats "mixed with" ints.

they're all either one or the other. probably floats. some of the floats just happen to not have any fractional part.

i'm not sure i fully understand your question... you want to print them out exactly as entered? i guess theres a number of ways you could do this.

one way would be to input them as strings, and store them in a string array, then convert them to the appropriate value when needed. ... or, along those lines, a structure where you have the "as enetered" string element, along with a floating point "value" element

is this making sense? is this relevant to your question?

.

Yup, a string was what i thought, but i wondered if i could have an array of floats that i can print out as integers if they don't have fractional parts. and if i could print a float to the last digit, without zeros at the end, for example if the input is 1.6 i print 1.6, not 1.60000

well, you can use format specifiers

"%.3f" for instance will print up to 3 decimal places but only if they are non-zero digits.

"%.03f" will always print 3 decimal places even if they are zero digits.

you cant have a single array of floats "mixed with" ints

You can have an array with different data types, you just need to point to them using void*

example:

``````void *array[] = {(int*)123, (char*)"Hello"};
cout << (int)array[0]; // prints 123
cout << (char*)array[1]; // prints "Hello"``````
commented: good call +3

aha. i knew someone was going to call me on that.

:P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.