Questions tagged [pset1-credit]

The tag has no usage guidance.

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

Pset1 Credit - Why is my code bypassing the Floor function inside If statement?

Here's my code- int f_1 = floor(N / 1000000000000000); int f_2 = floor(N / 1000000000000); int f_3 = floor(N / 100000000000000); int f_4 = floor(N / 10000000000000); if (...
0 votes
1 answer
49 views

Cs50 pset1 problem credit

I'm not able to take out the second digit of the credit number, how to do it for large numbers like 16 digit,15digit,14 digit?
0 votes
1 answer
138 views

Pset1:credit - converting a long to a string causes a segfault?

I keep getting a segfault, and help50 doesn't help. A lot of head scratching an googling later, I think I've narrowed it down to: you can't convert a long to a string. Is that true? The code in ...
0 votes
1 answer
77 views

Pset1 Credit- How should I proceed to add the sum of multiplied digits & further addition with remaining credit card numbers?

I can pretty much select the digits, multiply the digits by 2 & add the particular digits of the multiplied number. But as of now I can only print them not add them. I also have to add this sum to ...
0 votes
1 answer
25 views

PSET 1 - Credit, Mastercard validation failing

Trying to solve the Credit Question in PSET1, unable to get the mastercard number to validate. Attaching the code #include <cs50.h> #include <stdio.h> long get_card(void); int card_length(...
0 votes
1 answer
148 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
1 answer
69 views

Help in PSET1: Credit. Check50 not showing up

I finished (what I think) is a correct version of credit and when I submit, I only see marks for style and no check50 on the submit50 page. Also, when I do check50 in the terminal window, I get a "...
0 votes
1 answer
59 views

PSET1 - credit ,not satisfying all test cases ,please help

These are the test cases which my code doesn't satisfy ,can someone please help me out as i have absolutely no idea why it is happening. Some tips or advice would be handy. Thank you in advance. :( ...
0 votes
2 answers
14 views

can anyone help error check my luhns algorithm code?

i wrote this version of the credit card number checking code and it still gives me an error when i check it. apparently, it validates 4111111111111113 and 4222222222223 as visa numbers when theyre not....
1 vote
1 answer
42 views

Credit : the checksum is correct for <10 digits, but for14,15,16 digits getting negative checksum

The checksum is correct for less than 10 digits but for 14-16 digits it is coming back negative. What am I doing wrong? #include <cs50.h> #include <stdio.h> #include <math.h> int ...
0 votes
0 answers
136 views

Can anyone help me troubleshoot my code for the CS50 Credit problem? (**not trying to cheat, just need some help!)

This is the code I have written in c for the cs50 credit pset 1 problem. I am checking the length of numbers entered, and the first digits (AMEX 15 digits, starts with 34 or 37; MC 16 digits, starts ...
0 votes
2 answers
43 views

pset1-credit I can't find the issue with my code

the program prints invalid for valid card I know that my mistake is probably really dumb, but I can't find it (sorry for bad english) #include <cs50.h> #include <stdio.h> int main(void) { ...
0 votes
1 answer
24 views

I'm getting a floating point exception error in the credit code but I definitely haven't divided by 0

Here is the code: int sum1(long long n) { int sum1 = 0; int x = 0; for (long long i = 100; (n % i) <= n; i *= 100) { x = 2 * ( ( (n % i) - (n % (i / 10)) ) / (i / 10) ); ...
0 votes
1 answer
44 views

Week-1 problem set credit

I have started taking the CS5 lessons and while I run my code for the week-1 credit problem, the terminal always shows the output as "INVALID" or anything that I insert in the second last ...
0 votes
1 answer
109 views

pset1:Credit (always outputs INVALID)

Whenever I input any card number into the program it outputs INVALID. I think the issue has something to do with not finding the first digits (int fdig) correctly because I used a print function ...
0 votes
1 answer
37 views

there is a logical error I can't really catch up with

Output: Results for cs50/problems/2022/x/credit generated by check50 v3.3.7 :) credit.c exists :) credit.c compiles :) identifies 378282246310005 as AMEX :) identifies 371449635398431 as AMEX :) ...
0 votes
1 answer
144 views

Dealing with pset1's "credit" problem

I was trying to solve this problem. I did some coding: #include <cs50.h> #include <stdio.h> int get_digit_number(long card_number); int main(void){ bool valid; long card = get_long(&...
0 votes
1 answer
31 views

Need Help, why does my debug50 show a correct result but when i run the program, thus it shows a wrong answer

Here's my code #include <cs50.h> #include <stdio.h> #include <math.h> //1:26:36 / 2:24:59 int main(void) { long n; int exc; do { n = get_long("Enter your ...
0 votes
1 answer
96 views

credit.c I don't understand how to fix my code

I've been trying to figure out what's wrong with my code. I used printf so I could confirm whether or not the value of N is correct but it's coming out as completely different as what I would expect ...
0 votes
1 answer
75 views

CS50 Credit Pset problem- Code keeps looping back to ask for the credit card number

The following is my code for the Credit Pset from week 1 of CS50, it is not the complete solution to the problem (all the code does (rather is supposed to do) is for the user to enter a credit card ...
0 votes
1 answer
23 views

Credit problem: Opening parentheses not matched with closing

Though it might appear annoying, the program not compiling. To the best of my understanding, there is a closing parenthesis on line 37. Is it some cache related issue? https://drive.google.com/file/d/...
1 vote
1 answer
63 views

Function in C: How to create

#include <stdio.h> #include <cs50.h> int main(void) { long creditcardno; do { creditcardno = get_long("enter"); } while (creditcardno < 0); } The above code accepts ...
0 votes
1 answer
263 views

Could not find the following in the output: <class 'pexpect.exceptions.EOF'>

#include <stdio.h> #include <cs50.h> int main(void) { long creditcardno; do { creditcardno = get_long("enter"); if (creditcardno < 999999999999 || creditcardno ...
0 votes
1 answer
102 views

Credit card problem: Unable to calculate the sum of entered credit card no

#include <stdio.h> #include <cs50.h> int main(void) { long creditcardno; do { creditcardno = get_long("enter"); } while (creditcardno < 1000000000000 || creditcardno > ...
0 votes
2 answers
14 views

Unable to move to the next chunk of the problem

#include <stdio.h> #include <cs50.h> int main(void) { long creditcardno; do { creditcardno = get_long("enter"); } while (creditcardno < 1000000000000 || creditcardno > ...
1 vote
1 answer
126 views

Pset1- Credit: Length of the number by continuously dividing by 10

// Get card number long n = get_long("Number: "); // Count length int i = 0; long cc = n; while (cc > 0) { cc = cc / 10; i++; } Source: https://medium.com/swlh/cs50-pset-1-credit-...
0 votes
1 answer
72 views

Do-while code for long integer input

It is mentioned in the problem: American Express uses 15-digit numbers, MasterCard uses 16-digit numbers, and Visa uses 13- and 16-digit numbers. So with get_long, I perhaps need to restrict input ...
0 votes
1 answer
110 views

Segmentation Fault for PSet1 Credit in CS50

first time posting. I swear I looked for answers in other segmentation fault questions already, but I am new to programming and to troubleshooting/researching effectively. My PSet1 program "...
1 vote
1 answer
110 views

cs50 pset1 credit expected expression error

So, I have gotten rid of all the errors and got the code to the point to prompt the user for the credit card number and output an answer the only problem is the program falls thru to invalid every ...
0 votes
1 answer
28 views

expected expression error in pset1 credit for loop

I am getting a error in the following line long checksum = (long) for (int i=1; i < 8; i=i+2) { if (checksum > 9) { (((long) 2*(credit_number % (long) ...
0 votes
1 answer
52 views

Stuck with pset1 credit question. I don't know why I'm not able to get any "Valid" outputs when a valid card number is entered

#include <stdio.h> #include <cs50.h> #include <math.h> #include <stdlib.h> int main (void) { int count = 0; //Declare counter //Get input from user long number = get_long (&...
0 votes
1 answer
1k views

How do you find the first digit of a long number?

I wrote the following code to try to find the first digit of a long number (this is for the CS50x "Credit" exercise), but it's not working. Any tips? // Conditions and relational operators #...
0 votes
1 answer
170 views

PSET 1 Credit AMEX

I've calculated the Luhn's algorithm for all the credit cards and it works fine. The only issue I have is that the American Express cards which are tested don't fulfill the Luhn's algorithm! This is ...
0 votes
1 answer
2k views

How To Use a For Loop To Store Values Into Multiple Variables?

I'm working on the Credit problem set. Along the way, I've encountered a scenario where I want to use a for loop to store multiple values. If I type printf("%d", cc_number[p]); in that for loop, it ...
0 votes
1 answer
163 views

Credit.c works, but not completely?

So I finished credit.c today and was trying out different numbers from the paypal website the course provided and got some unexpected results and don't know what to do with it. When I type in valid ...
1 vote
2 answers
162 views

error at while loop cs50 Pset1 credit

I am getting an error at while loop it says error: '&&' within '||' [-Werror,-Wlogical-op-parentheses] while((credit % 10 >= 0) && (i < 15) || (i < 16)) here is my ...