Questions tagged [modulo]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
36 views

trying to check second to last digit— cs50 pset 1 #credit#

I am trying to understand the second to last digit thing, i think i have been coding wrong the whole time. take this example 45002136581 in the walk through the guy says we take 5 0 2 1 5 1. while i ...
0
votes
0answers
65 views

Stuck by problem set Credit, % operator

As a beginner I am stuck in de problem set Credit. Especially the % function is giving me trouble To better understand it, I tried to use the example of programming simplified to get the sum of digits....
0
votes
1answer
88 views

cash CS50 2020 pset1 modulo

I seem to be having trouble using modulo as conditions inside of while loops. int main() { float n; do { n = get_float("How much change is owed? "); } while(n < 0); int cents = round(...
0
votes
1answer
99 views

why do we use remainder 26 (%26)?

Why do we keep using the %26 in pset2 when working with Caesar and Vignere? I'm having trouble understanding why it would be helpful to know what the remainder is after dividing by 26?
0
votes
1answer
111 views

PSET1 - Credit Checksum Problem

{ long long l; do { l = get_long_long("Number: "); } while (l < 0); float count = 0; long long m = l; while( m != 0) { m /= 10; count+...
0
votes
1answer
130 views

PSet1 cash, modulo problem

Why does this give 19 instead of 20 when change = 4.2? Thanks.
0
votes
1answer
206 views

Pset1 Cash Understanding modulo operator and while loops

I'm trying to set up my solution to the Cash problem using modulo. The input seems to be working correctly so far. It only accepts positive numbers through the do..while loop. The problem I think I ...
0
votes
1answer
220 views

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

I am getting the following errors and I cannot figure out why. I've managed to work out the other bugs up until this. Would someone be able to point me in the correct direction? Kind regards, Sam ...
0
votes
1answer
61 views

Another modulo question for CS50 Caesar

If I turn my uppercase characters into a numeric list from 0-25 and then my lowercase from 26-61 and apply modulus 26, I am anticipating converting all lowercase into uppercase letters as all the ...
0
votes
1answer
224 views

Trying to make cash.c from pset 1 without mod

So I've made this program with modulus and it made sense to me, but when I ran it I got an error message saying I can't use mod on floats. Since then I've been trying to replace this: change = ...
1
vote
1answer
41 views

Output of characters at specific place place using uint_list

I am trying to make an output using 3 characters (vertical line, plus sign, minus sign) and using uint_list to increase or reduce the length. #include <stdio.h> #include <stdlib.h> #...
0
votes
1answer
327 views

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

I have a problem with a modulo in “Credit”. That is a part of my initial code: #include <stdio.h> #include <cs50.h> #include <math.h> int main(void) { //...
1
vote
2answers
91 views

Refactoring Pset1 Greedy Modulo

I've got Pset 1, 'Greedy' working, I just think I can refactor it better. How can I get rid of ints a, b, c and d? a = amount /25; amount = amount % 25; b = amount /10; amount = amount % 10; c = ...
0
votes
1answer
172 views

vigenere key wraparound issue

I'm really stuck on vigenere. I've gotten close, but I think there's an issue with the way I've set up the Key and how it wraps around. Here's my program: #include <cs50.h> #include <stdio....
0
votes
1answer
231 views

greedy with modulo

I've been working on my greedy with modulo for a while now and I'm not sure what I'm doing wrong.(For the moment I'm focusing on the part where I use integers to count the number of coins, skipping ...
0
votes
1answer
49 views

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

I am having trouble with pset2 vigenere problem. It it is as follows. if islower(plaintext[i]) //lower { printf("%c", (((plaintext[i] - 97) + (tolower(argv[1][counter]) ...
0
votes
1answer
84 views

Pset2 Vigenere z key stops functionning after e

I have been struggling a lot with vigenere and I am seeing the light. The only thing I have left to do is understanding how to take into account the z character when doing modulo 97. my code work with ...
0
votes
1answer
576 views

CS50 Pset 6 vigenere.py

I have written the following code for vigenere.py, but I do not know how to incorporate into my code the idea that after the for loop reaches the final character of the command-line argument, it ...
0
votes
2answers
90 views

Vigenere modulo not working

I am trying to make this output a character encrypted with a key(which is an int) it just outputs some numbers or something. printf("%c", (((p[i] - 65) + (k[j] - 65)) % 26) + 65;);
0
votes
1answer
101 views

pset2 Vigenere looping error

I've been working on this pset for a few weeks now and can't seem to figure out how to correctly apply modulo to wrap my cipher. When I run my program, I correctly cipher the first time around, think ...
0
votes
2answers
338 views

pset2 Vigenere Modulo

I'm don't understand how to use modulo to shift my characters. When I type 'Z', I get a '[' instead of 'A'. I read elsewhere that I need to shift the key AND the inputed text - yes? for (int i = 0, ...
0
votes
1answer
215 views

Typecasting with Modulo in Greedy

I'm having trouble getting the the modulo function to work in greedy using this code int result = 0.0; printf("SHOW ME WHAT YOU GOT: "); float paid = GetFloat(); while (paid >= 0.25) { ...
0
votes
1answer
202 views

Greedy; Pset 1 - Trouble creating modulo algorithm

int q=coins/25; //gives number of quarters int mq=coins%25; gives modulo quarters int md=mq/10; int mn=md/5; int mp=mn/1; printf("%d, %d, %d, %d,", q+md+mn+mp); So I've been able to prompt the user ...
0
votes
1answer
214 views

pset 2 vigenere help

I have been working on vigenere for a long time now, and here is my issue. plaintext cab with a keyword of ab returns ccbbbb. so, the plaintext is enciphering correctly but the last letter is ...
0
votes
1answer
216 views

Modulo not working in caesar

When I run my code, anytime I try to use the modulo function, I get a strange symbol for an answer. I can't post it because it wouldn't download, but it is a square with 4 numbers inside. Why am I ...
1
vote
2answers
176 views

Why is d = 185 to satisfy de = 1 mod m (where m = 924)? (Wk2, shorts: cryptography)

At the 6:50 min mark of this video: https://courses.edx.org/courses/HarvardX/CS50x3/2015/courseware/c0986764d695405f9d995f43b7c10676/5194906ad75c4edb9ecd401df372b8f3/ here's a screen shot, too: http:/...
0
votes
1answer
156 views

modulo returning wrong value in Greedy

The following code in my Greedy program (getting float from user simplified for forum purposes!): change = GetFloat(); // convert to int int cInt = round(change*100); // define arraw with values of ...
0
votes
2answers
1k views

Modulo not working in Greedy

I'm working on pset1 Greedy and am trying to use a modulo to eliminate the need for loops. The user inputs a float in the form of the "change" needed. This is converted into a whole number for easier ...
0
votes
2answers
739 views

How to wrap around the jth element in vigenere cipher efficiently?

I have seen a lot of solutions to this but still didn't found the efficient solution for wrapping around for the non-alphabet character in the text to be encrypted. What I did was jth position (...
7
votes
4answers
6k views

What's the point of the modulo operation in the Caesar cipher formula?

According to the problem set specification, the formula for encrypting a message using the Caesar cipher is: ci = (pi + k) % 26 I don't get why you need to do modulo 26. What does it even do here?
0
votes
1answer
48 views

how do I restrict cipher to alpha only - I am getting symbols that come after “z”

I am focusing on lower case only until I get it working, any help?? if(argc != 2) // if not two line commands prints error and stops program { printf("Please enter a single key"); return 1; }...
2
votes
4answers
802 views

How to calculate modulo?

From the cryptography video short(Week2) , can anybody tell how to compute the value of m = c^d (mod n) ? How do we find that 658^185(mod 989) equals 67 ?