如何使它工作? [英] How to make it work?

查看:79
本文介绍了如何使它工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个测试项目,我想跳转功能



this is a testing project, i want to jump around functions

#include <iostream>

using namespace std;

int function1()
{
    cout<<"function1 (2 or 3)"<<endl;
    int x;
    cin>>x;
    return x;
}
int function2()
{
    cout<<"function2 (1 or 3)"<<endl;
    int x;
    cin>>x;
    return x;
}
int function3()
{
    cout<<"function3 (1 or 2)"<<endl;
    int x;
    cin>>x;
    return x;
}

int main()
{
    while(true)
    {
        switch(function1())
        {
        case 2:
            {
            switch(function2())
                {
                case 1: function1();
                case 3: function3();
                }
            }
        case 3:
            {
            switch(function3())
                {
                case 1: function1();
                case 2: function2();
                }
            }
        }
    }
}

推荐答案

I认为您正在寻找一种方法将每个函数的返回值传递给开关,以便可以执行所需的函数。试试这个:



I think you are seeking a way to pass the return value of each function to the switch so that the desired function can be executed. Try this:

int main()
{
	int f = 1;
	while (true)
	{

		switch (f)
		{

			case 1:
				f = function1();
				break;

			case 2:
				f = function2();
				break;

			case 3:
				f = function3();
				break;

			default:
				break;
		}
	}
}


这篇关于如何使它工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆