本规范存在问题...请帮助 [英] Problem With this Code...Please Help

查看:36
本文介绍了本规范存在问题...请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,告诉用户输入

矩形的两边。从那个程序将使用*输出一个

矩形的drwaing ...这是我的问题。假设我输入5和10表示

两侧..这就是输出。


********** *

* *

* *

* *

**********


我不知道为什么它会在第一行添加asterk ..相同

如果我进入另外2个边,就会发生这种情况。等等...任何帮助都是

appriciated !!!


这是我的代码到目前为止:我使用Turbo因此.h


#include< iostream.h>

#include< conio.h>

#include< iomanip.h>

int main()

{

clrscr();


int side1,side2;


cout<<"请输入第1面:" ;;

cin>> side1;

cout<< 请输入第2面:" ;;

cin>> side2;


for(int a = 1; a< side1; a ++)

cout<<" *" ;;


for(int b = 1; b< =(side2-1); b ++)

cout<<" *"<< setw(side1-1)<<" *"<< endl;


for(int c = 1; c< = side1; c ++)

cout<<" *" ;;

return 0;

}

解决方案



" 1111111111" <诶*** @ hotmail.com>在留言中写道

新闻:3f ************************** @ posting.google.c om ...

我正在编写一个程序,告诉用户输入一个
矩形的两边。从那个程序将使用*输出一个
矩形的drwaing ...这是我的问题。假设我输入5和10表示
两侧..这就是输出。

********** *
* *
* *
* *
**********

我不知道为什么它会在第一行添加asterk ..相同
如果我进入另外两个方面就会发生等等......任何帮助都会很有用!!!

这是我的代码到目前为止:我使用Turbo因此.h

#include< iostream.h>
#include< conio.h>
#include< iomanip.h>
int main()
{
clrscr();

int side1,side2;

cout<<"请输入第1面:" ;;
cin>> side1;
cout< <"请输入第2面:" ;;
cin>> side2;

for(int a = 1; a< side1; a ++)
cout<< ;" *" ;;

for(int b = 1; b< =(side2-1); b ++)
cout<<" *"<< setw(side1-1)<<" *"<< endl;

for(int c = 1; c< = side1; c ++)
cout<< ;" *";

返回0;
}




我会用这样的东西:


for(int x = 0; x< side1; ++ x)

{

for(int y = 0; y< side2 ; ++ y)

{

//如果在边缘上绘制*

if((x == 0)|| (y == 0)|| (x == side1-1)|| (y == side2-1))

cout<< " * QUOT; ;

其他

cout<< "英寸; //一个空格

}

cout<<结束;

}


Allan




" 1111111111" ; <诶*** @ hotmail.com>在留言中写道

新闻:3f ************************** @ posting.google.c om ...

我正在编写一个程序,告诉用户输入一个
矩形的两边。从那个程序将使用*输出一个
矩形的drwaing ...这是我的问题。假设我输入5和10表示
两侧..这就是输出。

********** *
* *
* *
* *
**********

我不知道为什么它会在第一行添加asterk ..相同
如果我进入另外两个方面就会发生等等......任何帮助都会很有帮助!!!




因为你忘了在第一个结束后输出换行符

行(以及最后一行结束后)。额外的星号实际上是下一行的第二个星号

。还有其他一些问题,但是你会花点时间来解决这些问题。


这里有一个教训,电脑做的就是你告诉他们的,而不是你想的*你想要告诉他们的。


john


2004年5月18日11:58:28 -0700, eh***@hotmail.com (1111111111)写道:

我正在编写一个程序,告诉用户输入一个
矩形的两边。从那个程序将使用*输出一个
矩形的drwaing ...这是我的问题。假设我输入5和10表示
两侧..这就是输出。

********** *
* *
* *
* *
**********

我不知道为什么它会在第一行添加asterk ..相同
如果我进入另外两个方面就会发生等等......任何帮助都会很有用!!!

这是我的代码到目前为止:我使用Turbo因此.h

#include< iostream.h>
#include< conio.h>
#include< iomanip.h>
int main()
{
clrscr();

int side1,side2;

cout<<"请输入第1面:" ;;
cin>> side1;
cout< <"请输入第2面:" ;;
cin>> side2;

for(int a = 1; a< side1; a ++)
cout<< ;" *英寸;


上面,你打印一行太少''*'作为顶行,然后通过忘记发出新行后复合

混乱(b = 1; b< =(side2-1); b ++)
cout<<" * << setw(side1-1)<<" *"<< endl;

for(int c = 1; c< = side1; c ++)
cout<<"" *" ;;

返回0;
}




-

Leor Zolman --- BD软件--- www.bdsoft.com

C / C ++,Java,Perl和Unix的现场培训

C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html


I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"''s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.

********** *
* *
* *
* *
**********

I dont know why it is adding that asterk on the first row.. Same
thing happens if I enter 2 other sides. Etc... Any help would be
appriciated!!!

Here is my code so far: I use Turbo hence the .h

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int main()
{
clrscr();

int side1, side2;

cout<<"Please enter side 1: ";
cin>>side1;
cout<<"Please enter side 2: ";
cin>>side2;

for(int a=1; a<side1; a++)
cout<<"*";

for(int b=1; b<=(side2-1); b++)
cout<<"*"<<setw(side1-1)<<"*"<<endl;

for(int c=1; c<=side1; c++)
cout<<"*";
return 0;
}

解决方案


"1111111111" <eh***@hotmail.com> wrote in message
news:3f**************************@posting.google.c om...

I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"''s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.

********** *
* *
* *
* *
**********

I dont know why it is adding that asterk on the first row.. Same
thing happens if I enter 2 other sides. Etc... Any help would be
appriciated!!!

Here is my code so far: I use Turbo hence the .h

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int main()
{
clrscr();

int side1, side2;

cout<<"Please enter side 1: ";
cin>>side1;
cout<<"Please enter side 2: ";
cin>>side2;

for(int a=1; a<side1; a++)
cout<<"*";

for(int b=1; b<=(side2-1); b++)
cout<<"*"<<setw(side1-1)<<"*"<<endl;

for(int c=1; c<=side1; c++)
cout<<"*";
return 0;
}



I would use something like this:

for (int x=0; x<side1; ++x)
{
for(int y=0; y<side2; ++y)
{
// if on an edge draw an *
if ((x==0) || (y==0) || (x==side1-1) || (y==side2-1))
cout << "*" ;
else
cout << " "; // a space
}
cout << endl;
}

Allan



"1111111111" <eh***@hotmail.com> wrote in message
news:3f**************************@posting.google.c om...

I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"''s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.

********** *
* *
* *
* *
**********

I dont know why it is adding that asterk on the first row.. Same
thing happens if I enter 2 other sides. Etc... Any help would be
appriciated!!!



Because you are forgetting to output a newline after the end of the first
row (and after the end of the last row). The extra asterisk is actually the
second asterisk on the next row. There are some other problems but you''ll
probably figure out those once you''ve fixed this one.

There''s a lesson here, computer do exactly what you tell them to, not what
you *think* you''ve told them to.

john


On 18 May 2004 11:58:28 -0700, eh***@hotmail.com (1111111111) wrote:

I am writing a program that tells users to enter 2 sides of a
rectangle. From that the program will output a drwaing of the
rectangle using "*"''s... Here is my problem. Say I enter 5 and 10 for
the 2 sides.. This is what is output.

********** *
* *
* *
* *
**********

I dont know why it is adding that asterk on the first row.. Same
thing happens if I enter 2 other sides. Etc... Any help would be
appriciated!!!

Here is my code so far: I use Turbo hence the .h

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
int main()
{
clrscr();

int side1, side2;

cout<<"Please enter side 1: ";
cin>>side1;
cout<<"Please enter side 2: ";
cin>>side2;

for(int a=1; a<side1; a++)
cout<<"*";
Above, you print one too few ''*''s for the top row, and then compound the
confusion by forgetting to emit a newline after that line.
-leor

for(int b=1; b<=(side2-1); b++)
cout<<"*"<<setw(side1-1)<<"*"<<endl;

for(int c=1; c<=side1; c++)
cout<<"*";
return 0;
}



--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html


这篇关于本规范存在问题...请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆