小编Lem*_*zer的帖子

如何生成 1 和用户输入的数字之间的随机数?

如何创建一个从 1 -> 生成十个随机数的程序RAND_MAX?

RAND_MAX必须是用户输入的数字。

#include <iostream>
#include <stdlib.h>

int main()
{
    using namespace std;
    int x;
    int y;


    Random:
    {
        x = rand();
        cout << x << endl;
    }

    y = y + 1;
    if (y == 10) {
        return 0;
    }

    goto Random;
}
Run Code Online (Sandbox Code Playgroud)

c++ random

3
推荐指数
1
解决办法
2万
查看次数

我应该在这里使用goto声明吗?

一位优秀的绅士告诉我,goto语句不好,但我不知道我怎么不能在这里使用它:

int main()
{   
   using namespace std;
   int x;
   int y;
   int z;
   int a;
   int b;
   Calc: //How can i get back here, without using goto?
   {
   cout << "To begin, type a number" << endl;
   cin >> x;
   cout << "Excellent!" << endl;
   cout << "Now you need to type the second number" << endl;
   cin >> y;
   cout << "Excellent!" << endl;
   cout << "Now, what do you want to do with these numbers?" << endl;
   cout …
Run Code Online (Sandbox Code Playgroud)

c++ goto

0
推荐指数
1
解决办法
291
查看次数

不同文件中的函数无法正常工作

我做了一个调用这个函数的程序.我知道这是因为"Int Strength已被调用"出现在输出框中.但是,它不会改变我告诉它要做的值.我希望它从main()获取整数值,然后使用它们并返回新值.我使用的头文件只包含"int strength(int a,int s,int i)"

int strength(int a, int s, int i)
{
    using namespace std;
    cout << "Int Strength has been called" << endl;
    a = a + i;
    s = s - i;
    return a;
    return s;
}
Run Code Online (Sandbox Code Playgroud)

c++ function-call

-2
推荐指数
1
解决办法
61
查看次数

标签 统计

c++ ×3

function-call ×1

goto ×1

random ×1