[英]cs50 mario pyramid error when check50
I"m doing the Mario pyramid task for cs50 course, the code works but I get errors when I do check50. Someone advised at a moment to replace spaces with characters to see whats wrong and I did (a instead of space) but I still can't figure it out. There seems to be a problem with the spaces but i dont cant figure out what it is.我正在为 cs50 课程做马里奥金字塔任务,代码有效,但当我做 check50 时出现错误。有人建议用字符替换空格以查看有什么问题,我做了(a 而不是空格)但我仍然想不通。空间似乎有问题,但我不知道它是什么。
Expecting the following on standard out —
# #
## ##
... but received the following on standard out instead
— a# #
## ##
... but received the following on standard out instead —
aaaaaaaaaaaaaaaaaaaaaa# #
aaaaaaaaaaaaaaaaaaaaa## ##
aaaaaaaaaaaaaaaaaaaa### ###
aaaaaaaaaaaaaaaaaaa#### ####
aaaaaaaaaaaaaaaaaa##### #####
aaaaaaaaaaaaaaaaa###### ######
aaaaaaaaaaaaaaaa####### #######
aaaaaaaaaaaaaaa######## ########
aaaaaaaaaaaaaa######### #########
aaaaaaaaaaaaa########## ##########
aaaaaaaaaaaa########### ###########
aaaaaaaaaaa############ ############
aaaaaaaaaa############# #############
aaaaaaaaa############## ##############
aaaaaaaa############### ###############
aaaaaaa################ ################
aaaaaa################# #################
aaaaa################## ##################
aaaa################### ###################
aaa#################### ####################
aa##################### #####################
a###################### ######################
####################### #######################
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height;
int row;
int hash;
int space;
do
{
printf("Height:");
height =get_int();
}
while (height<0 || height>23);
for (row = 0; row < height; row++)
{
for (space = (height-row-2); space>= 0; space--)
{
printf ("a");
}
for (hash = 0; hash <= row; hash++)
{
printf ("#");
}
printf(" ");
for (hash=0; hash <= row; hash++)
{
printf("#");
}
printf("\n");
}
}
//i tweak your code a bit and now i get the right piramide thanks for //sharing your code //我稍微调整了你的代码,现在我得到了正确的 piramide 感谢 //分享你的代码
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height;
int row;
int hash;
int space;
do
{
height=get_int("size:");
}
while (height<0 || height>8);
for (row = 0; row < height; row++)
{
for (space = (height-row-2); space>= 0; space--)
{
printf (" ");
}
for (hash = 0; hash <= row; hash++)
{
printf ("#");
}
printf("\n");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.