#include <stdio.h> #include <cs50.h> #include <math.h>
int main (void);
{
float dollar;
do;
{
dollar = get_float ("Where is my change: ");
} while ("dollar <= 0");
int cents = round (dollar * 100);
int coins = 0;
while (cents >= 25);
{
cents -= 25;
coins++;
}
while ("cents >= 10 ");
{
cents -= 10;
coins++;
}
while ("cents >= 5 ");
{
cents -= 5;
coins++;
}
while ("cents >= 1");
{
cents -= 1;
coins++;
}
printf("You need at least %i coins", coins);
return();
}
Add a comment
|
1 Answer
This is a very common newbie problem. The problem lies here:
int main (void);
The semicolon is breaking the code. It must be removed. The correct form is this:
int main (void)
{
//program code....
}
That semicolon marks the line as a function signature. When you get to functions, you'll understand this more. ;-)
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)
-
That didn't work when I erase the semicolon I got 6 other errors pointing to other semicolon Commented Oct 1, 2020 at 22:29
-
Another lesson learned. Just because more errors appear doesn't mean that things got worse. Compilers make multiple passes through code. Sometimes they stop cold on an error. Other times, they look for more errors. In this case, that one error was masking more errors to come. Yes, you've fixed the semicolon problem. Now, you need to fix the next 6 problems, and more, if they appear! Don't get discouraged. It gets easier. You'll stop making these errors fairly soon. Tip: fix the errors in sequence. Sometimes one error can cause 30 more errors. Fixing that first one would erase those 30.– Cliff BCommented Oct 1, 2020 at 22:50
-
Interestingly, it looks like the remaining problems are still semicolons that don't belong. Those semicolons at the end of the while statements terminate the while loops, disconnecting the code within curly braces that follows from the while loops. Also, putting the test conditions within the parentheses on the while statements corrupts the test. Remove the double quotes. Double quotes around anything say that "this is a literal text string".– Cliff BCommented Oct 1, 2020 at 22:54
-
A couple of suggestions: Review where semicolons should NOT be used. Review the structure and setup of do/while and while loops, and how test conditions should be written. Finally, spend some quality time running code through style50 until you get the hang of properly formatting code. It will serve you well later.– Cliff BCommented Oct 1, 2020 at 23:00
-