C++ 布尔值不变?[C+;+;]

C++ 布尔值不变?[C+;+;],c++,C++,主要内容: //导入所需的库、标题并定义问答变量的大小 #包括 #包括 #包括 #包括“lib/script.h” #定义字符串大小为1000 //初始化临时虚拟变量和问答变量 字符串问题[字符串大小]; 字符串回答[字符串大小]; //初始化ShowMain菜单功能 void showMainMenu(); int main(){ //显示主菜单 showmain菜单(); 返回退出成功; } void showmain菜单(){ std::cout看看您的问题,您似乎忘记了为每个开关盒添加

主要内容:

//导入所需的库、标题并定义问答变量的大小
#包括
#包括
#包括
#包括“lib/script.h”
#定义字符串大小为1000
//初始化临时虚拟变量和问答变量
字符串问题[字符串大小];
字符串回答[字符串大小];
//初始化ShowMain菜单功能
void showMainMenu();
int main(){
//显示主菜单
showmain菜单();
返回退出成功;
}
void showmain菜单(){

std::cout看看您的问题,您似乎忘记了为每个开关盒添加一个中断

请查看下面有关使用交换机的MSDN文章


如果您习惯于VB.NET,您可能会习惯于case语句是自包含的。C需要中断,否则,即使开关不匹配,逻辑也会转到下一个语句。

欢迎使用StackOverflow!请注意问题应该是自包含的(即:它们可能包含外部资源,但在没有外部资源的情况下应负责)。您可以尝试提供。请提取一个最小的示例,然后在此处内联发布。就目前情况而言,您的问题与主题无关,请阅读发布指南以了解更多信息。此外,标签不应出现在标题中,这是有其独立位置的原因。“当我验证选项的更改时”是什么意思是什么意思?你在谈论什么选项?你如何更改它们?你如何验证更改?
//Imports needed libraries, headers and defines the size of the question and answer variables

#include <iostream>
#include <cstdlib>
#include <string>
#include "lib/script.h"
#define STRING_SIZE 1000

//Initalises the temporary dummy variable and the question + answer variables
std::string questions[STRING_SIZE];
std::string answers[STRING_SIZE];

//Initalises showMainMenu function
void showMainMenu();


int main() {
    //Shows the main menu
    showMainMenu();
    return EXIT_SUCCESS;
}

void showMainMenu() {
    std::cout << "Welcome to Stack.! To get started, type in the number from 1-4 that you desire!\n\n";
    std::cout << "1. Create new stack\n";
    std::cout << "2. Open existing stack\n";
    std::cout << "3. Export existing stack\n";
    std::cout << "4. Options\n\n";
    std::cout << "";
    //Assigns the user input to the dummy variable initalised earlier
    std::cin >> dummy.usrInput;
    //Reads the usrInput and figures out what the user wanted
    switch(dummy.usrInput){
        case 1:
            createNewStack();
        case 2:
            openExistingStack();
        case 3:
            exportExistingStack();
        case 4:
            showOptions();
        default:
            std::cout << "That was not a valid input. Press enter to continue... ";
            std::cin.get();
            clearScreen();
    }
}
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>

struct usrOptions{
    bool autosave, randomisedCards;
    std::string autosaveOn, randomOn;
}option;

struct dummies{
    int usrInput;
}dummy;

inline void clearScreen(){
    #ifdef _WIN32
        std::system("cls");
    #else
        std::system ("clear");
    #endif
}

inline void saveUserStack(){

}

void createNewStack(){

}

void openExistingStack(){

}

void exportExistingStack(){

}

void showOptions(){
    clearScreen();
    switch(option.autosave){
        case 0:
            option.autosaveOn = "off";
        case 1:
            option.autosaveOn = "on";
    }
    switch(option.randomisedCards){
        case 0:
            option.randomOn = "off";
        case 1:
            option.randomOn = "on";
    }

    std::cout << "1. Autosave is currently " << option.autosaveOn;
    std::cout << "\n2. Randomised cards are currently " << option.randomOn;
    std::cout << "\n\nWhich option do you wish to change (please enter in the form of an integer): ";
    std::cin >> dummy.usrInput;
    switch(dummy.usrInput){
        case 1:
            std::cout << "Are you sure you wish to change the option for autosave? 0 = no 1 = yes: ";
            std::cin >> dummy.usrInput;
            switch(dummy.usrInput){
                case 0:
                    clearScreen();
                    showOptions();
                default:
                    switch(option.autosave){
                        case 0:
                            option.autosave = 1;
                        default:
                            option.autosave = 0;
                    }
                    showOptions();
                }
        case 2:
            std::cout << "Are you sure you wish to change the option for randomised cards? 0 = no 1 = yes: ";
            std::cin >> dummy.usrInput;
            switch(dummy.usrInput){
                case 0:
                    showOptions();
                default:
                    switch(option.randomisedCards){
                        case 0:
                            option.randomisedCards = 1;
                        case 1:
                            option.randomisedCards = 0;
                    }
                    showOptions();
            }
        default:
            showOptions();
    }    
    std::cout << "Autosave is currently " << option.autosaveOn;
}