Quick actions

cmd+k|ctrl+k

Navigation

Languages

First third, last third, half, and first quarter

Snippet info

Language

Cpp

Visibility

public

Author

kaniaslan27

Created

2024-11-12T17:29:25.747001Z

Updated

2025-10-02T19:07:50.155713Z

#include <iostream>

int minutes(float pra);
float digi(int mins);
float round(float a);
void aesthetics(float a);

int main(void){
    float magh, fajr;
    std::cout << "The first number that should be given is the time of maghrib\n";
    std::cin >> magh;
    std::cout << "The second time that should be given is the time for fajr\n";
    std::cin >> fajr;

    //measuring the time in between the two times
    float between = minutes(fajr) + 24*60 - minutes(magh);
    float first_third = round((digi(minutes(magh) + between/3)));
    float last_third = round((digi(minutes(magh) + (between/3)*2)));
    float half_ending = round((digi(minutes(magh) + between/2)));
    float first_quarter = round((digi(minutes(magh) + between/4)));
    std::cout << "The time for the ending of the first half of the night is: ";
    aesthetics(first_third);
    std::cout << "The start of the last third of the night is: ";
    aesthetics(last_third);
    std::cout << "The time for the ending of the first half of the night is: ";
    aesthetics(half_ending);
    std::cout << "The ending of the first quarter of the night is: ";
    aesthetics(first_quarter);
}

//Function convering times to  minutes
int minutes(float pra){
    int time = (int (pra))*60 + (pra - int (pra))*100;
    return time;
}

//digitises the new time from minutes
float digi(int mins){
    float a = (int (mins))%60;
    float time = (int ((int (mins))/60)) + a/100;
    if (time >= 24){
        time -= 24;
    }
    return(time);
}

//A function for rounding it out to two decimals
float round(float a){
    float b = int(a * 100);
    return float(b)/100;
}

//An aesthetical-function
void aesthetics(float a){
    if (a < 10){
        std::cout << '0';
        if (1 < (int (a * 100))%10){
            std::cout << a << std::endl;
        }
        else{
            std::cout << a << "0" << std::endl;
        }
    }
    else {
        if (1 < (int (a * 100))%10){
            std::cout << a << std::endl;
        }
        else{
            std::cout << a << "0" << std::endl;
        }
    }
}
INFO