Thread: Any help with bool and float

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    2

    Any help with bool and float

    Hi.I'm trying to "make" triangle validation with bool and float.And that is OK.My problem is how to "mutate" bool return into string so I can printf it.Yes,I'm total beginner,but I try. Thank's in advance.
    TF.txt open in Sublime or ...
    Code:
    #include <stdio.h>
    #include <cs50.h>
    
    bool val_tri(float x, float y, float z);
    
    int main(void)
    {
        float x = get_float("first side: ");
        float y = get_float("second side: ");
        float z = get_float("third side: ");
    
    
        printf("triangl is %s.\n", tf);
    }
    
    bool val_tri(float x, float y, float z)
    {
        if (x < 0 || y < 0 || z < 0)
        {
            return false;
        }
        if ((x + y <=z) || (x + z <= y) || (y + z <= x))
        {
            return false;
        }
    
        return true;
    }
    Attached Files Attached Files
    • File Type: txt TF.txt (504 Bytes, 18 views)
    Last edited by Salem; 04-25-2020 at 02:08 PM. Reason: Inlined the code

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    953
    If you want to print the value of a bool you can either print it as an int where it will print as 0 for false and 1 for true, or you can print it as a string.
    Code:
    // as int
    printf("bool: %d\n", (int)bool_value);
     
    // as string
    printf("bool: %s\n", bool_value ? "true" : "false");
    If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

  3. #3
    Registered User
    Join Date
    Apr 2020
    Posts
    2
    As a string...Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 09-23-2018, 04:17 PM
  2. Replies: 5
    Last Post: 03-11-2014, 02:43 PM
  3. BOOL bool ? unresolved external symbol
    By xwielder in forum C Programming
    Replies: 6
    Last Post: 05-20-2008, 08:39 AM
  4. How get bool's from std::vector<bool>
    By 6tr6tr in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2008, 05:24 AM
  5. Interesting: bool != BOOL
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 01-09-2002, 11:09 AM

Tags for this Thread