Hot answers tagged

6

Well, you wanted some tips, so here are a few thoughts on it. You know that you have to create the correct number of rows, you have that part. Now, you need to think about how to create the spaces and hashes. Well, break it down into smaller and smaller parts. You need to think about how to build a given row. OK, that's a smaller part. What is a row? It'...


2

Using the 5 pyramid as a guide: Height: 5          ##        ###      ####    #####  ###### The psuedocode is straightforward: for height times    for s times        ...


2

Multiple things. if plaintext.isupper(): you meant i.isupper(). plaintext.isupper() would check whether the whole string is upper-case, which it is not, but it also isn't completely lower-case, so the else path triggers. i is a bad choice for a variable name, and if it is used as such, it usually means an integer, not a string as in your code. For a ...


2

place 2 "for loops", 1 for spaces and 1 for dashes inside your row "for loop"... tip its a double loop in a loop. your ("\n") needs to be outside your two inner loops. now getting it to work is a different story! but that's a way for it to be done.


1

string input = get_string("Text:"); //getting input from the user int len = strlen(input); //determining the length of the string int space = 0; //declaring a variable to count whitespaces for (int i = 0; i < len; i++) //declaring a for loop to check each element of the string { if (input[i] == ' ') { space++; ...


1

Don't make things complicated. for x in range (height): print((height-x - 1)*' ' + (x+1)*'#')


1

Your staircase has the stairs going down to the right. They're supposed to go up from the left. Perhaps a review of the assignment specification is in order? There's a second problem lying in wait, but it's an easy fix so I'll let you find it. You might also want to temporarily replace the space with a printable character for testing if you can't see ...


1

Let's see if I can point you in the right direction here. For spaces, for (int s = i-1; s >= r; s--) is giving you one too many spaces every time because of the test condition. Let's check out a height of 1. You want 0 spaces, but look what happens. i=1, so s= 1-1 = 0. On the first iteration, s >= i-1 tests as 0 >= 0 which evaluates as true. So, it ...


1

You don't need it to be height-i-1 and you can just do height-i Your hashes can be i+1 rather than i+2 If you do this, I think it will work as planned. Hope this helps, Ian


1

They should work exactly the same. printf(" "); will print a single space, the content between the double quotes. printf("%s"," ") will grab the first parameter " "after the format string, "%s" and substitute it in for the placeholder %s. While the mechanism is a little different, it has the same result of printing a single space. I am suspicious about ...


1

It wasn't completely clear, but it seems that you are having a problem with your key advancing when non-alpha letters are processed. If this is the case, the relevant code is what isn't shown. My best guess is that you are using the same index to advance through both your plaintext and your key. Because the key is not always used, (when non-alphas are ...


1

I spent many hours on this and finally solved it tonight... just haven't ran it through the CS50 checker yet. BLUF:(Bottom line up front:) your heading in wrong direction thinking of multiplication. You will be building a ("FOR LOOP") with two inner ("FOR LOOPS"). So many people say and advise to use pencil paper and eraser (will be erasing A LOT!) but ...


Only top voted, non community-wiki answers of a minimum length are eligible