注册 登录
编程论坛 C++教室

嵌套循环问题

mouse14521 发布于 2017-05-01 23:46, 2134 次点击
帮看一下下面代码,按了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;
}

2 回复
#2
rjsp2017-05-02 08:25
play;
改为
play( magic );
#3
mouse145212017-05-02 13:24
回复 2楼 rjsp
多谢,搞定了
1