我正在编写一个程序,它接收一个字符和数字的行并显示它,它的写入功能但有一些错误,我现在不知道原因。
#include <iostream>
using namespace std;
void chap(char,int,int);
int mian()
{
int x,z,q;
char y;
cout<<"do you want run program?";
cin>>x;
while(x!=0)
{
cout<<"enter your character: \n";
cin>>y;
cout<<"\nenter the number of lines: \n";
cin>>z;
cout<<"enter 1 for normal pattern and enter 0 for unnormal pattern : \n";
cin>>q;
cout<< chap(y,z,q);
cout<<"do you want run program?";
cin>>x;
}
}
void chap(char y,int z,int q)
{
if(q==1)
{
for (int i=0;i<z;i++)
{
for(int j=0;j<=i;j++)
{
cout<<y;
}
cout<<"\n";
}
}
if(q==0)
{
for(int i=z;i!=0;i--)
{
for(int j=i;j<=i;j--)
{
cout<< y;
}
cout<<"\n";
}
}
}
在编译时,我收到以下错误消息:
E:\ c ++ test ++ \ test1 \ main.cpp | 18 |错误:不匹配'operator&lt;&lt;'在 'std :: cout&lt;&lt; chap(((int)y),z,q)'| -
如果我能够编译并运行程序,这是所需的行为:输入character = p line = 5并显示:
p
pp
ppp
pppp
ppppp
答案 0 :(得分:0)
这应该做的工作。
#include <iostream>
using namespace std;
void chap(char,int,int);
int main()
{
int x,z,q;
char y;
cout<<"do you want run program?";
cin>>x;
while(x!=0)
{
cout<<"enter your character: \n";
cin>>y;
cout<<"\nenter the number of lines: \n";
cin>>z;
cout<<"enter 1 for normal pattern and enter 0 for unnormal pattern : \n";
cin>>q;
chap(y,z,q);
cout<<"do you want run program?";
cin>>x;
}
}
void chap(char y,int z,int q)
{
if(q==1)
{
for (int i=0;i<z;i++)
{
for(int j=0;j<=i;j++)
{
cout<<y;
}
cout<<"\n";
}
}
if(q==0)
{
for(int i=z;i>0;i--)
{
for(int j=0;j<i;j++)
{
cout<< y;
}
cout<<"\n";
}
}
}