Skip to main content

Command Palette

Search for a command to run...

Day 99/100 100 Days of Code

Jumping Ball

Published
1 min read
Day 99/100 100 Days of Code
C

AKA Chris, is a software developer from Athens, Greece. He started programming with basic when he was very young. He lost interest in programming during school years but after an unsuccessful career in audio, he decided focus on what he really loves which is technology.

He loves working with older languages like C and wants to start programming electronics and microcontrollers because he wants to get into embedded systems programming.

I removed the mini-app and applied the physics formula in the GetResults function. I removed the location argument and the mini-app submodule.

#include "results.h"
// Special thanks to the following SO post for providing a very nice solution
// https://stackoverflow.com/questions/12911299/read-csv-file-in-c
// Strings, pointers, and going out of scope:
// https://stackoverflow.com/questions/32652050/mutating-array-of-char-using-a-function-but-string-values-change-after-function

struct Results GetResults(char *value)
{
    struct Results results;
    if (value == NULL || value[0] == '\0')
    {
        results.maxHeight = 0;
        results.timeToMaximumHeight = 0;
        results.timeToLand = 0;
        results.doResultsExist = false;
        return results;
    }

    int getValue = atoi(value);
    double g = 9.8;

    if (getValue > 100)
    {
        results.maxHeight = 0;
        results.timeToMaximumHeight = 0;
        results.timeToLand = 0;
        results.doResultsExist = false;
        return results;
    }

    for (int i = 0; i < 3; i++)
    {

        switch(i)
        {
            case 0:
                results.maxHeight = pow((double)getValue, 2) / g; 
                break;
            case 1:
                results.timeToMaximumHeight = (double)getValue / g;
                break;
            case 2:
                results.timeToLand = pow(results.maxHeight/g, 2); 
                break;
        }
    }

    results.doResultsExist = true;

    return results;
}