input double but returning a character/string
I have tried to input a double number from the main and return a character/string using a function but i have not been able to do that as yet. can anyone help me on this?
You need to convert the double to a string. The precise implementation details depend on yoru design. You can use stringstream objects to automate the conversion. Otherwise, use sprintf() to convert double to a char array buffer.
I am familiar with casting in java but not in C++ .... is it possible to show me a code to convert? i mean if it is some what done like it is done in java.
you cant cast it, strings are arrays of chars in c/c++.
so either study sprintf as danny sais or create a function to convert it.
Depending on what compiler and libraries you use you can look into itoa or IntToStr.
If you wish to create your own function to convert it, I can give you a hint, to make a single digit a char you can do this: char DigitAsChar = (char)MySingleDigit+'0';
MySingleDigit beeing a int.
Then it will add the value of the char '0' to the value of the digit so if the digit = 5 it will be '5' (the char) instaid and the it cast's to a char so it will accept setting a char to the number representation of the character.
I'm sorry if I over- or under explain.
ahhh ok thanks for letting me know about casting.
i kept trying and before i checked for messages here i made the solution :)
it was very simple....since i am new i did not know the proper syntax for coding a return function.
what i have done is i have made a string function. I am sending an integer value and returning a string according to the if statement.
By WackoWolf in forum C++
Last Post: 10-17-2005, 05:22 PM
Last Post: 10-03-2005, 12:57 AM
Last Post: 09-26-2005, 06:09 PM
Last Post: 08-06-2003, 04:46 AM
By George Gilbert in forum vb.announcements
Last Post: 08-19-2001, 12:34 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center