Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.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++ - Fatal编程技术网

C++ 如果计数器为>;然后我想打印一个字母,等于字母中的计数器

C++ 如果计数器为>;然后我想打印一个字母,等于字母中的计数器,c++,C++,我正在制作一个非图,但有一个要求是,当计数器大于9时,我希望打印字母,因此,例如,如果计数器为10,我希望打印a、11-B等。这是我的函数,hulp值放在不同函数的数组中 int nono::letter(int counter){ char hulp; if (counter > 9){ return hulp ='a'+counter; } } 我将其放入的函数: void nono::makeDis (){ bool empty

我正在制作一个非图,但有一个要求是,当计数器大于9时,我希望打印字母,因此,例如,如果计数器为10,我希望打印a、11-B等。这是我的函数,hulp值放在不同函数的数组中

int nono::letter(int counter){
    char hulp;
     if (counter > 9){
        return hulp ='a'+counter;
     }
}
我将其放入的函数:

void nono::makeDis (){
    bool empty = false;
    int Dis;
    int counter = 0;
    for (int j = 0; j <= width; j++){
        for (int i = 0; i <= height; i++){
            column[j][i] = 0;
        }
    }
    for (int j = 0; j <= width; j++){
        besc = 0;
        counter=0;
        for (int i = 0; i <= height; i++){
            if (denono[i][j]==1){
                counter++;
            }else if(counter > 0 && counter <10){
                column[j][besc]=counter;
                besc++;
                counter = 0;
            }else if(counter>9){
                column[j][besc]=letter(counter);
                besc++;
                counter=0;
            }

        }
    }
}
void nono::makeDis(){
bool empty=false;
int Dis;
int计数器=0;

对于(int j=0;j该
hulp
变量的使用已过时,使您的代码看起来可疑。为什么不按如下方式执行此操作:

char nono::letter(int counter){
     if (counter > 9){
        return 'A'+counter;
     }
     else return '0' + counter;
}

最重要的是,你提到了你想看的内容,你展示了你迄今为止创建的程序,但是当你运行该程序时,你实际看到了什么?(这可能有助于我们了解你的问题在哪里(顺便问一下,是什么问题?)

您需要先从计数器中减去10,然后再将其添加到“a”中,以确保您使用的偏移量正确。而且,由于您已经在检查呼叫代码中的数字us是否高于9,因此不需要在此处执行此操作。因此,您的代码简化为以下内容:

char nono::letter(int counter){
   return 'A'+counter-10;   
}
同样在print函数中,确保在打印列数组值之前将其转换为char,如下所示:

void nono::printDescColumn(){
bool notEmpty;
int x =0;

cout << "   ";
for (int j = 0; j < width; j++) {
    controlBeschKolom(j);
    if(valideK[j]) {
        cout << "V ";
    }
    else{
        cout << "  ";
    }
}
cout << endl;
for (int i = 0; i < height; i++){
    notEmpty=false;
    cout<< "   ";
    for (int j = 0; j < width; j++){
        ///controlBeschKolom(j);
        if(column[j][i]!=0 ){
            if(column[j[[i]>9) {
                cout<<char(column[j][i]<<" ";
            }else{
                cout<<column[j][i]<<" ";
            }
            notEmpty=true;
        }else{
            cout<<"  ";
        }
    }
    cout<<endl;
    if(!notEmpty){
        break;
    }

}
void nono::printdescolumn(){
布尔不空虚;
int x=0;

它看起来像是约束一个数字或(的代码)吗一个字符。这看起来很难在以后使用。你为什么不把像
5
这样的小数字转换成它们对应的字符
'5'
?或者,你可能需要它来存储普通数字,以后在打印时才切换到字母。我不理解你代码的逻辑。分配一个字符是没有用的仅用于返回的变量:
return hulp='a'+counter;
…您可以直接返回
a'+counter
,而无需重新发布问题。您可以编辑旧的。请发布一个。什么是
colom
?声明在哪里?这仍然会给我65而不是您将返回类型从int更改为char。您的代码说int nono::letter(int counter){…需要是char nono::letter(int counter){…这是错误的:假设
counter
是8,然后返回ASCII(63),它不是字符“8”,而是“?”(问号)是的,我这样做了是的,但是在代码中,他只在计数器大于9的情况下调用函数。因此,如果
存储
int
s而不是
char
s,则不可能发生这种情况。然后,此更改将不会使OPs代码打印letters@idclev463035818:
int
char
很容易反转:65在与字母“A”相同。显然,你需要确保语法正确。我知道,但显然不是,整个问题是如何将一些整数打印为字母
void nono::printDescColumn(){
bool notEmpty;
int x =0;

cout << "   ";
for (int j = 0; j < width; j++) {
    controlBeschKolom(j);
    if(valideK[j]) {
        cout << "V ";
    }
    else{
        cout << "  ";
    }
}
cout << endl;
for (int i = 0; i < height; i++){
    notEmpty=false;
    cout<< "   ";
    for (int j = 0; j < width; j++){
        ///controlBeschKolom(j);
        if(column[j][i]!=0 ){
            if(column[j[[i]>9) {
                cout<<char(column[j][i]<<" ";
            }else{
                cout<<column[j][i]<<" ";
            }
            notEmpty=true;
        }else{
            cout<<"  ";
        }
    }
    cout<<endl;
    if(!notEmpty){
        break;
    }

}