Questions tagged [modulo]

The tag has no usage guidance.

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

Why is my C modulo code giving repeating identical output?

I am wondering why my output repeats before it gets to the final output: #include <cs50.h> #include <stdio.h> #include <math.h> int main(void) { long bignum = 4300123488893756; ...
user avatar
  • 103
0 votes
1 answer
66 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 ...
user avatar
0 votes
0 answers
84 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....
user avatar
  • 7
0 votes
1 answer
161 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(...
user avatar
0 votes
1 answer
143 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?
user avatar
0 votes
1 answer
143 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+...
user avatar
  • 3
0 votes
1 answer
134 views

PSet1 cash, modulo problem

Why does this give 19 instead of 20 when change = 4.2? Thanks.
user avatar
0 votes
1 answer
245 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 ...
user avatar
0 votes
1 answer
353 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 ...
user avatar
  • 3
0 votes
1 answer
66 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 ...
user avatar
0 votes
1 answer
257 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 = ...
user avatar
1 vote
1 answer
43 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> #...
user avatar
  • 113
0 votes
1 answer
379 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) { //...
user avatar
  • 28
1 vote
2 answers
98 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 = ...
user avatar
0 votes
1 answer
174 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....
user avatar
  • 7
0 votes
1 answer
239 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 ...
user avatar
0 votes
1 answer
53 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]) ...
user avatar
  • 7
0 votes
1 answer
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 ...
user avatar
0 votes
1 answer
586 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 ...
user avatar
  • 121
0 votes
2 answers
96 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;);
user avatar
0 votes
1 answer
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 ...
user avatar
0 votes
2 answers
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, ...
user avatar
0 votes
1 answer
217 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) { ...
user avatar
  • 19
0 votes
1 answer
227 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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
  • 4
0 votes
1 answer
233 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 ...
user avatar
1 vote
2 answers
181 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:/...
user avatar
0 votes
1 answer
163 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 ...
user avatar
0 votes
2 answers
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 ...
user avatar
0 votes
2 answers
773 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 (...
user avatar
  • 1
9 votes
4 answers
9k 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?
user avatar
  • 305
0 votes
1 answer
50 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; }...
user avatar
2 votes
4 answers
964 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 ?
user avatar