Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C+中绘制空心钻石+;使用两个函数_C++_Function - Fatal编程技术网

C++ 如何在C+中绘制空心钻石+;使用两个函数

C++ 如何在C+中绘制空心钻石+;使用两个函数,c++,function,C++,Function,因此,我和我的团队已经在这个项目上工作了几天,我们可以在进入它时也画出顶部,但它没有运行,我们不知道为什么它不会运行。 第一个功能是绘制顶部,第二个功能是绘制底部。 顶部似乎画得很好,我不知道为什么代码甚至不能运行 #include<iostream> using namespace std; void drawTopPart(int userNum); void drawBottomPart(int userNum); int main() { //declaratio

因此,我和我的团队已经在这个项目上工作了几天,我们可以在进入它时也画出顶部,但它没有运行,我们不知道为什么它不会运行。 第一个功能是绘制顶部,第二个功能是绘制底部。 顶部似乎画得很好,我不知道为什么代码甚至不能运行

#include<iostream>
using namespace std;

void drawTopPart(int userNum);
void drawBottomPart(int userNum);

int main() {
    //declarations
    int userNum;

    //get user input
    cout << "Enter an odd number from 1 to 15: ";
    cin >> userNum;

    //output
    drawTopPart(userNum);
    drawBottomPart(userNum);

    cout << endl;

    system("pause");
    return 0;
}

void drawTopPart(int userNumPar) {
    int z = 1;
    int size;

    cin >> size;

    for (int i = 0; i <= size; i++) {
        for (int j = size; j>i; j--) {
            cout << " "; 
        }
        cout << "*"; 

        if (i>0) {
            for (int k = 1; k <= z; k++) {
                cout << " ";
            } z += 2; cout << "*";
        }
        cout << endl; 
    }
}

void drawBottomPart(int userNumPar){
    int z -= 4;
    int size;

    cin >> size;

    for (int i = 0; i <= size - 1; i++) {
        for (int j = 0; j <= i; j++) {
            cout << " ";
        }
        cout << "*";

        for (int k = 1; k <= z; k++) {
            cout << " ";
        }

        z -= 2;

        if (i != size - 1) {
            cout << "*";
        }
    }
#包括
使用名称空间std;
void drawTopPart(int userNum);
void drawBottomPart(int userNum);
int main(){
//声明
int userNum;
//获取用户输入
cout>userNum;
//输出
drawTopPart(userNum);
drawBottomPart(userNum);
大小;
对于(int i=0;i i;j--){

你有两个主要的错误。 首先,

int z-=4;
有语法错误。您可以更改它
int z=17;

第二,你忘了这里的endl

if (i != size - 1) {
cout << "*";
}
cout << endl;
if(i!=size-1){

你不能输入两次
cin>>size;
吗?请使用函数参数,不要在输出函数中请求用户输入。这是不可用的。int z-=4是怎么回事;为什么你把
userNumPar
作为参数,但从不使用它?你甚至编译过这个程序一次吗??
if (i != size - 1) {
cout << "*";
}
cout << endl;