c++ - 通过循环 C++ 打印报价单

标签 c++ loops

<分区>

我对c++的了解少得可怜。很长一段时间以来,我一直被这个简单的问题难倒,只想指出正确的方向。该程序的基础是让用户选择一个数字 1-5,然后根据他们的决定打印出多次报价。因此,如果他们选择数字 4,它将显示 4 次报价。

这是我目前所拥有的:

#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

int PickNumber()
{
    int i;
    cout << "Please Enter a Number From 1 to 5:";
    cin >> i;
    for (int j = 0; j < i; j++)
    {
        cout << "Congrats!";
    }
    return i;
}
int main()
{
    _getch();
    return 0;
}

最佳答案

只是为@molbdnilo、@Rietty 和@Gox 已经解决的这个问题添加一个答案:PickNumber() 函数没有在main 函数中调用。

只需将 PickNumber() 调用添加到 main 函数即可。

int main() {
    PickNumber();
    return 0;
}

关于c++ - 通过循环 C++ 打印报价单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54499039/

相关文章:

c++ - 构建行为排序函数

c++ - std::copy 毫无异常(exception)地导致错误

c++ - GetWindowTextW 无法获取宽字符串

loops - 我怎样才能 "while loop"一个 Axios GET 调用直到满足条件?

javascript - for循环和执行顺序

c - 如何在源代码级别自动展开源代码中的循环?

android - 破坏方法 Android 的问题

loops - 如何使用启动它的键停止自动热键中的无限循环

c++ - 这个赋值运算符后面的 & 是什么意思?

c++ - 在 X11 窗口上移动窗口事件