CS50 2022, pset1 Cash. A serious compiling issues using VS code

Viewed 14

I am taking the CS50 2022 online course, and I was working on problem set 1, titled "Cash". Now, mind you, I haven't finished tweaking my code, and checking for mistakes or re-editing anything, because I can't seem to get passed the compiling error I keep receiving. I will show you my code work in a minute, but first take a look at these instructions, I received.

"In cash.c, we’ve implemented most (but not all!) of a program that prompts the user for the number of cents that a customer is owed and then prints the smallest number of coins with which that change can be made. Indeed, main is already implemented for you. But notice how main calls several functions that aren’t yet implemented! One of those functions, get_cents, takes no arguments (as indicated by void) and returns an int. The rest of the functions all take one argument, an int, and also return an int. All of them currently return 0 so that the code will compile. But you’ll want to replace every TODO and return 0; with your own code."

I can't compile my code via terminal, check50 or help50. I have tried everything, even following a YouTube tutorial down to every word.

Now, here's my work and the error will be shown down below:

#include <cs50.h>
#include <stdio.h>

int get_cents(void);
int calculate_quarters(int cents);
int calculate_dimes(int cents);
int calculate_nickels(int cents);
int calculate_pennies(int cents);

int main(void)
{
  // Ask how many cents the customer is owed
  int cents = get_cents();

  // Calculate the number of quarters to give the customer
  int quarters = calculate_quarters(cents);
  cents = cents - quarters * 25;

  // Calculate the number of dimes to give the customer
  int dimes = calculate_dimes(cents);
  cents = cents - dimes * 10;

  // Calculate the number of nickels to give the customer
  int nickels = calculate_nickels(cents);
  cents = cents - nickels * 5;

  // Calculate the number of pennies to give the customer
  int pennies = calculate_pennies(cents);
  cents = cents - pennies * 1;

  // Sum coins
  int coins = quarters + dimes + nickels + pennies;

  // Print total number of coins to give the customer
  printf("%i\n", coins);
}

int get_cents(void)
{
  int cents;
  do
  {
     cents = get_cents("Cents owed: ");
  }
  while(cents < 0);
  return cents;
}

int calculate_quarters(int cents)
{
  return cents/25;
}

int calculate_dimes(int cents)
{
  return cents/10;
}

int calculate_nickels(int cents)
{
  return cents/5;
}

int calculate_pennies(int cents)
{
  return cents/1;
}

The issue for me is the int cents = get_cents(); on line 13. I have tried different variation to this line. With the first one being blank between the brackets.

2nd = int cents = get_cents(int cents);

3rd = int cents = get_cents ("Cents owed: ");

Errors I got in order:

1st error =

*cash.c:43:27: error: too many arguments to function call, expected 0, have 1

cents = get_cents("Cents owed: "); (This is the statement inside the do while loop, so you are not confused, not line 13 at the top)

cash.c:38:5: note: 'get_cents' declared here int get_cents(void) ^ 1 error generated.*

2nd error =

cash.c:13:27: error: expected expression

int cents = get_cents(int cents); (this is line 13)

3rd error =

cash.c:13:27: error: too many arguments to function call, expected 0, have 1

int cents = get_cents("Cents owed: ");

cash.c:4:5: note: 'get_cents' declared here

int get_cents(void);

Note: I understand if I got the logic wrong after the do while loop statements. (The calculate_quarters etc.) I was still working on solving the problem. I am a beginner, go easy on me :). I am also aware of the correct solution, but even with the correct solution (like the youtube tutorials I watched), I STILL cant compile my code. I want to submit it for my grades, but the cs50 bot will reject it since my code won't compile. Please, tell me what I am doing wrong or how I can fix this? Any help is much appreciated!!!

Also one last thing to note, I have tried deleting the VS code software and re-installing it. I have used a browser version on chrome via Github and I have tried updating the codespaces and rebuilding it. Many times...this is seriously driving me crazy :(

P.S sorry for the long post...my first time here too lol. Also, thank you so much, for taking the time to read this and solve the issue!

0 Answers
Related