注册 登录
编程论坛 C++教室

帮忙看下这个程序, 出错的提示也看不太懂

jansonying 发布于 2014-05-15 09:03, 509 次点击
#include <iostream.h>
void main()
{
int i, j, k, l, n ;
cout<<"输入允许前面空出的行数:" ;
cin>>n;
for(j=1; j<=4; j++)
{
 for(i=1; i<=n; i++)
     cout<<' ';
 for(l=1; l<=8-2j; l++)
     cout<<' ';
 for(k=1; k<=2j-1; k++)
     cout<<'*';
cout<<endl;
}
for(j=1; j<=3; j++)
{for(i=1; i<=n; i++)
     cout<<' ';
 for(k=1; k<=7-2j; k++)
     cout<<'*';
cout<<endl;
}
}
7 回复
#2
wp2319572014-05-15 09:04
帮忙看下这个程序, 出错的提示也看不太懂


那为什么不把错误提示也一起贴出来呢
#3
peach54602014-05-15 09:05
出错提示在哪里?
#4
wp2319572014-05-15 09:06
那个什么命名空间没有声明  直接使用cin cout 之类的语句  能过才怪
#5
jansonying2014-05-15 09:30
回复 2 楼 wp231957
提示如下:

--------------------Configuration: test3 - Win32 Debug--------------------
Compiling...
test3.cpp
E:\test3\test3.cpp(11) : error C2059: syntax error : 'bad suffix on number'
E:\test3\test3.cpp(11) : error C2146: syntax error : missing ';' before identifier 'j'
E:\test3\test3.cpp(11) : error C2146: syntax error : missing ')' before identifier 'l'
E:\test3\test3.cpp(11) : error C2059: syntax error : ';'
E:\test3\test3.cpp(11) : error C2059: syntax error : ')'
E:\test3\test3.cpp(12) : error C2146: syntax error : missing ';' before identifier 'cout'
E:\test3\test3.cpp(13) : error C2059: syntax error : 'bad suffix on number'
E:\test3\test3.cpp(13) : error C2146: syntax error : missing ';' before identifier 'j'
E:\test3\test3.cpp(13) : error C2146: syntax error : missing ')' before identifier 'k'
E:\test3\test3.cpp(13) : warning C4552: '-' : operator has no effect; expected operator with side-effect
E:\test3\test3.cpp(13) : error C2059: syntax error : ';'
E:\test3\test3.cpp(13) : error C2059: syntax error : ')'
E:\test3\test3.cpp(14) : error C2146: syntax error : missing ';' before identifier 'cout'
E:\test3\test3.cpp(20) : error C2059: syntax error : 'bad suffix on number'
E:\test3\test3.cpp(20) : error C2146: syntax error : missing ';' before identifier 'j'
E:\test3\test3.cpp(20) : error C2146: syntax error : missing ')' before identifier 'k'
E:\test3\test3.cpp(20) : error C2059: syntax error : ';'
E:\test3\test3.cpp(20) : error C2059: syntax error : ')'
E:\test3\test3.cpp(21) : error C2146: syntax error : missing ';' before identifier 'cout'
Error executing cl.exe.

test3.obj - 18 error(s), 1 warning(s)

#6
yxq2110462014-05-15 09:34
没有2j这种说法吧,应该是2*j
#7
jansonying2014-05-15 09:38
可以运行了 谢了啦
#8
wp2319572014-05-15 09:39
#include <iostream>    //这个没有.h

using namespace std;   //这个  必须的

void main()
{
    int i, j, k, l, n ;
    cout<<"输入允许前面空出的行数:" ;
    cin>>n;
    for(j=1; j<=4; j++)
    {
        for(i=1; i<=n; i++)
            cout<<' ';
        for(l=1; l<=8-2*j; l++)   //这个 编译器不能识别2j 这个东东 下同
            cout<<' ';
        for(k=1; k<=2*j-1; k++)
            cout<<'*';
        cout<<endl;
    }
    for(j=1; j<=3; j++)
    {for(i=1; i<=n; i++)
    cout<<' ';
    for(k=1; k<=7-2*j; k++)
        cout<<'*';
    cout<<endl;
    }
}
1