#True/False or 0/1 Enabler

5 messages · Page 1 of 1 (latest)

static cosmos
#

Im not sure about this, its my first actual functioning and cool project i made yeah its not really a big project, but its a start, well here it is:

// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
int main() {
    int arr[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    while (true){  
        for(int i = 0; i < 9; i++){
            std::cout << arr[i] << " \n";
        }
        
        int choice;
        int temp;
        std::cout << "choose which to turn on (1-9): ";
        std::cin >> choice;
        
        switch (choice){
            case 1:
                arr[0] = temp;
                arr[0] = 1;
                break;
            case 2:
                arr[1] = temp;
                arr[1] = 1;
                break;
            case 3:
                arr[2] = temp;
                arr[2] = 1;
                break;
            case 4:
                arr[3] = temp;
                arr[3] = 1;
                break;
            case 5:
                arr[4] = temp;
                arr[4] = 1;
                break;
            case 6:
                arr[5] = temp;
                arr[5] = 1;
                break;
            case 7:
                arr[6] = temp;
                arr[6] = 1;
                break;
            case 8:
                arr[7] = temp;
                arr[7] = 1;
                break;
            case 9:
                arr[8] = temp;
                arr[8] = 1;
                break;
        }
    }
}

code is messy i guess but its nice to see that it works, adding switching off functions soon though.

static cosmos
#

could make the code 100x easier but its too much brain usage for my knowledge level

pliant crow
#

What does temp do? 😄

obsidian wing
knotty tapir
#
#include <array>
#include <iostream>
#include <string>

int main() {
    std::array<int, 9> arr = {};

    while (true) {
        for (auto i : arr) {
            std::cout << i << " \n";
        }

        int choice;
        std::cout << "choose which to turn on (1-9): ";
        std::cin >> choice;

        arr[choice - 1] = 1;
    }
}

:p