4 votes

why do we use remainder 26 (%26)?

% 26 will always give you a number between 0 and 25. The Caesar algorithm works on the assumption that your letters A-Z (or a-z) are represented by the numbers 0-25, so if you have 'z' (25) and a key ...
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

cash CS50 2020 pset1 modulo

Why are you using modulo for this? It produces an unreliable result in this usage. Further, the actual numbers don't make sense. The modulo function returns the remainder after an integer division. ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

PSET1 - Credit Checksum Problem

test.c:35:49: error: invalid operands to binary expression ('double' and 'double') printf("%lld\n", ((l / (pow(10.00, i))) % 10)); ~~~~~~~~~~~~~~~~~~~~~ ^ ~~ 1 error ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

PSet1 cash, modulo problem

Welcome to the world of (binary) floating point. A value like 4.2 cannot be precisely represented in binary, it would be represented by an infinite sequence of binary digits. Obviously we don't have ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

Pset1 Cash Understanding modulo operator and while loops

You have created an infinite loop. If the loop starts, it will never exit the loop. It tests the value contained in amount to decide to continue or exit, but since the value of amount is not changed ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Pset 2 Caesar: "invalid operands to binary expression ('string' (aka 'char *') and 'int')"

In that formula, use p[i], the ith character of p, not p itself.
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

Another modulo question for CS50 Caesar

I would suggest that you convert both your uppercase and lowercase chars into an index value of 0-25. That is the premise of the caesar formula.
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

Trying to make cash.c from pset 1 without mod

Please have another look at the second hint of this exercise (https://docs.cs50.net/2018/x/psets/1/cash/cash.html#hints). After you have followed that advise, you will be able to use the modulo ...
Peter Pesch's user avatar
1 vote
Accepted

Output of characters at specific place place using uint_list

If you want to print something different based on a condition, you need to use a conditional like an if. As written this program will only ever output (sign) and 5 dashes. Full stop. This does not ...
DinoCoderSaurus's user avatar
1 vote
Accepted

PSET1 / Credit / Modulo problem / Error: invalid operands to binary expression ('double' and 'double')

the definition of the pow function says that it returns a double that is the reason of your error, since the operator modulo requires integers, it is possible that it works if we do a casting although ...
MARS's user avatar
  • 5,169
1 vote

Refactoring Pset1 Greedy Modulo

You could simply use coins as the variable that holds the coin value and add to it with each equation. coins = 0; coins += amount/25; ... coins += amount/10 .... etc etc. Then, at the end, coins ...
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

vigenere key wraparound issue

Take a close look at this line and think very carefully about what the modulo operation is being applied to: int cipherKey = (((key[i]) - 'A') % KeyLen); It coverts a key letter to a number between ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

greedy with modulo

You're creating multiple shadow variables in the code. A shadow variable is a new var with the same name as one that has been created earlier, but the new var is created in a place where it will have ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

strange output in vigenere. Even when done by hand to add ascii values

We have 26 characters in English alphabet, so use %26 and not %25. Also, note what you apply that %26 to, you seem to apply it to tolower(argv[1][counter]) - 97 only instead of to the whole sum.
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

Pset2 Vigenere z key stops functionning after e

By the let me tell you that your program is not working at all It's showing error something like this b.c:16:10: runtime error: null pointer passed as argument 1, which is declared to never be ...
Rahul's user avatar
  • 252

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