Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Double variable function problem...

DakkonDakkon Member Posts: 2
I need to send the variable (double) into the function as a char*

void changecolor(char* word, int color){
textcolor(color); //changes text to the color given through the argument
cprintf("%s", word); //outputs the string in the given color
textcolor(LIGHTGRAY); //change color back to the default light gray
} //end void changecolor


tried this:


char* mon;
mon = (char)monthly_interest;
changecolor(mon, color);


monthly_interest is a double, so why and where do I go wrong? How can I fix it? thanks!

Comments

  • pingpongpingpong Member Posts: 937
    You need sprintf..
    char mon[80];
    sprintf(mon, "%lf", monthly_interest);
    changecolor(mon, color);

    Look up the flags for sprintf for controlling the position of the floating points etc... for example, "%.3lf" will have 3 floating points.

    : I need to send the variable (double) into the function as a char*
    :
    : void changecolor(char* word, int color){
    : textcolor(color); //changes text to the color given through the argument
    : cprintf("%s", word); //outputs the string in the given color
    : textcolor(LIGHTGRAY); //change color back to the default light gray
    : } //end void changecolor
    :
    :
    : tried this:
    :
    :
    : char* mon;
    : mon = (char)monthly_interest;
    : changecolor(mon, color);
    :
    :
    : monthly_interest is a double, so why and where do I go wrong? How can I fix it? thanks!
    :

  • DakkonDakkon Member Posts: 2
    I owe you a beer =D

    Its work!
  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _________ < http://forcoder.org /> free video tutorials and ebooks about { Go Java Visual Basic Visual Basic .NET Scratch Ruby C++ Assembly MATLAB Delphi C# Perl PHP C Objective-C Swift R PL/SQL Python JavaScript D LabVIEW Kotlin Rust Hack Bash Awk SAS Ada Transact-SQL Apex Lua VBScript F# ABAP Prolog Dart Scala ML Scheme Alice Clojure Lisp Fortran COBOL Logo Julia Crystal FoxPro Erlang } _________

Sign In or Register to comment.