注册 登录
编程论坛 VC++/MFC

C++循环嵌套问题

mouse14521 发布于 2017-05-01 23:57, 2377 次点击
最近看一个教程
《C++捷径教程》 里面有一个循环嵌套的例子调试不出来,请帮看下为什么按2后不运行Play

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

using namespace std;


void play(int m)
{
    int t, x;
    for (t = 0; t < 100; t++) {
        cout << "Guess the number: ";
        cin >> x;
        if (x == m) {
            cout << " Right   \n";
            return;
        }
        else if (x < m) {
            cout << "Too low \n";
        }
        else cout << "Twoo High \n";
    }
    cout << "You'v used up all your queses. Try again. \n";
}



int main()
{
    int option;
    int magic;

    magic = rand();

    do {
        cout << "1. Get a nuew magic number\n";
        cout << "2. Play\n";
        cout << "3.Quit\n";
    do{
        cout << "Enter your choice:";
        cin >> option;
    } while (option < 1 || option>3);

    switch (option)
    {
    case 1:
        magic = rand();
        break;
    case 2:

        break;
    case 3:
        cout << "Goodbye\n";
        break;
    }
    play;
    }while (option != 3);
    return 0;
}

1 回复
#2
mouse145212017-05-02 13:23
知道了, 函数没有初始化参数,改成

play(0)


就好了
1