Just a backup of a small C program that I use for invoicing. Only relevant to Sweden. https://www.programiz.com/online-compiler/6EGyjJgEXkxw0

This program generates text that I paste into an Illustrator document. The reason that I need something like this is that I’m not willing to pay for an invoicing program, invoices in Google Sheets look awful, and Adobe Illustrator is uselesss for typing and editing text, and does also not provide spreadsheet capabilities.

// C Program: Räkna ut moms för upp till 20 varor
// © 2024, Electric Gauntz / andreas@9bit.se 

#include <limits.h>
#include <stdio.h>
#include <math.h>


struct Row { 
    float price;
    int amount;
    float total;
};

struct Row rows[20]; 


void one_row(float vat_percent) {
    static int index = 0;
    static char buffer[20][200]; // Max 20 lines, max 200 characters per line

    const int ROW_MAX = 20;
    if(index >= ROW_MAX) {
        return;
    }
    
    float price;
    int amount;

    // ---- User input ----
    
    printf("Rad %i Pris: ", index + 1);
    scanf("%f", &price);
    
    if(index > 0) {
        while (price == 0) {
            printf("Rad %i raderad\n\n", index);
            index--; // Delete last row
    
            printf("Rad %i Pris: ", index + 1);
            scanf("%f", &price);
        }
    }
    
    printf("Rad %i Antal: ", index + 1);
    scanf("%i", &amount);

    // ---------------------

    rows[index].price = price;
    rows[index].amount = amount;
    rows[index].total = price * amount;

    // printf("\n\tProdukt / Tjänst  \tPris\tAntal\tTotalt\n");

    float vat_value_sum = 0;
    float net_sum = 0;

    printf("\n");
    
    for(int i = 0; i < index + 1; i++) {
        printf("%i)\t", i + 1);
        printf("Benämning\t");
        printf("%.2f\t", rows[i].price);
        printf("%i\t", rows[i].amount);
        printf("%.2f\n", rows[i].total);

        net_sum += rows[i].total; // Add all lines
    }

    vat_value_sum = net_sum * vat_percent; // Add all lines
    
    printf("\n");
    printf("\tNetto:\t%.2f\n", net_sum);
    printf("\tMoms 25% (beräknad på %.2f):\t%.2f\n", net_sum, vat_value_sum);
    printf("\n");
    printf("\tSumma att betala:\t%.2f Kr\n", round(net_sum + vat_value_sum));
    printf("\n");
    
    index++;
}



int main() {
    float vat_percent = 0.25;

    while(1) {
        one_row(vat_percent);
    }

    return 0;
}

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.