-
input double but returning a character/string
Hi everyone,
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?
Thank you
-
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.
Danny Kalev
-
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.
GL Thomas.
-
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.
Similar Threads
-
By WackoWolf in forum C++
Replies: 4
Last Post: 10-17-2005, 04:22 PM
-
Replies: 3
Last Post: 10-02-2005, 11:57 PM
-
Replies: 1
Last Post: 09-26-2005, 05:09 PM
-
Replies: 2
Last Post: 08-06-2003, 03:46 AM
-
By George Gilbert in forum vb.announcements
Replies: 0
Last Post: 08-19-2001, 11:34 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks