lundi 9 octobre 2023

How can i program a c++ code where it does a pattern of diamonds

This is a practice lab where i have to use loops like for, while, do while. and with the loops im supposed to output a pattern with * like triangle shapes made out of * but on this one, it looks like i have to make hollow diamonds but more than just one this is how the output of the code should look like

so far i havent gotten far ahead since i have to make diagonal lines to make a diamond shape instead of simply just making a diamond shape heres the code of what i have so far

#include <iostream>

int main() {
    const int size = 30;
    const int distance = 10;

    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
            if ((i - j) % distance == 0) {
                std::cout << "*";
            } else {
                std::cout << " ";
            }
        }
        std::cout << std::endl;
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire