Question:
help in C please, error and need help correcting it ASAP?
Ryan
2010-02-10 15:39:11 UTC
my code is this :

#include
int main(void)
{
double amount = 0.0;
double numTens = 0;
double numFives = 0;
double numOnes = 0;
double numQuarters = 0;
double numDimes = 0;
double numNickels = 0;
double numPennies = 0;
int change_due = 0.0;


printf("This program computes the change to be given\n");
printf("for a purchase paid for with a $20 bill.\n");
printf("(The purchase must be less than or equal to $20)\n");
printf("Enter your purchase amount:");
scanf("%lg", &amount);
printf("Purchase amount is %lg ", amount);

change_due = (20.00 - amount);
printf("Change due is %d ", change_due);

while( amount >= 10.00 )
{
numTens++;
amount = 10.00;
printf("Tens: %f ", numTens);
}
while( amount >= 5.00 )
{
numFives++;
amount = 5.00;
printf("Fives: %f ", numFives);
}
while( amount >= 1.00 )
{
numOnes++;
amount = 1.00;
printf("Ones: %f ", numOnes);
}
while( amount >= 0.25 )
{
numQuarters++;
amount = 0.25;
printf("Quarters: %f ", numQuarters);
}
while( amount >= 0.10 )
{
numDimes++;
amount = 0.10;
printf("Dimes: %f ", numDimes);
}
while( amount >= 0.05 )
{
numNickels++;
amount = 0.05;
printf("Nickels: %f ", numNickels);
}
while( amount >= 0.01 )
{
numPennies++;
amount = 0.01;
printf("Pennies: %f ", numPennies);
}

while( amount < 0.0 )
{
printf("Please enter an amount greater than zero\n");
printf("and less than or equal to $20");
return 1;
while( amount > 20.0 )
{
printf("Please enter an amount greater than zero\n");
printf("and less than or equal to $20");
return 1;
}
return 0;
}


it is only two error messages away from compiling:

change.c:80: error: expected declaration or statement at end of input
change.c:80: warning: control reaches end of non-void function

PLEASE help soon, how do i fix this?????
Four answers:
Ratchetr
2010-02-10 15:46:29 UTC
I think you're missing a closing } for the while( amount < 0.0 ) loop.



You'll have a few other issues to address once it compiles.
RadioScarecrow
2010-02-10 16:07:34 UTC
without making too many changes to your code:



#include

int main(void)

{

double amount = 0.0;

double numTens = 0;

double numFives = 0;

double numOnes = 0;

double numQuarters = 0;

double numDimes = 0;

double numNickels = 0;

double numPennies = 0;

double change_due = 0.0;





printf("This program computes the change to be given\n");

printf("for a purchase paid for with a $20 bill.\n");

printf("(The purchase must be less than or equal to $20)\n");

printf("Enter your purchase amount:");

scanf("%lg", &amount);

printf("Purchase amount is %lg\n", amount);



change_due = (20.00 - amount);

printf("Change due is %f\n", change_due);



while( change_due >= 10.00 )

{

numTens++;

change_due -= 10.00;

}

printf("Tens: %g\n", numTens);



while( change_due >= 5.00 )

{

numFives++;

change_due -= 5.00;

}

printf("Fives: %g\n", numFives);



while( change_due >= 1.00 )

{

numOnes++;

change_due -= 1.00;

}

printf("Ones: %g\n", numOnes);



while( change_due >= 0.25 )

{

numQuarters++;

change_due -= 0.25;

}

printf("Quarters: %g\n", numQuarters);



while( change_due >= 0.10 )

{

numDimes++;

change_due -= 0.10;

}

printf("Dimes: %g\n", numDimes);



while( change_due >= 0.05 )

{

numNickels++;

change_due = -0.05;

}

printf("Nickels: %g\n", numNickels);

while( change_due >= 0.01 )

{

numPennies++;

change_due = -0.01;

}

printf("Pennies: %g\n", numPennies);





if( amount < 0.0 )

{

printf("Please enter an amount greater than zero\n");

printf("and less than or equal to $20");

return 1;

}

if( amount > 20.0 )

{

printf("Please enter an amount greater than zero\n");

printf("and less than or equal to $20");

return 1;

}

return 0;

}



Have a look and see what i have changed and why.



A lot of mistakes:



-what's the point in going into the while loop if you don't decrease the change_due after adding a coin?

-no need to use while loops for a 1 time condition. Use if instead.

-change due can't be an int! its a decimal...needs to be float or double.

-your counters only need to be ints. You can't have half a coin.

-bring the printf statements out of the loop. you only need to print once, not on every iteration.

-you could also use some if statements to make the program just print out the coins who's frequency is > 0.
jplatt39
2010-02-10 15:48:12 UTC
There is definitely a right brace (}) missing at the end of while(amount < 0.0). There may be others missing. When you get those two errors it usually means you have the wring number of braces.
hutts
2016-12-11 14:53:31 UTC
genuine that is the corrected code, even with the reality that it keeps to be incomplete. // Kristen Soos //This software computes a food bill #comprise iostream #comprise iomanip utilizing namespace std; const double TAXRATE = .08; const double TIPRATE = .15; void getinfo (double &no_meals, double &cost_meal, double &cost_dessert, double &roomfee, double &deposit); void calculatecost (double cost_meal, double cost_dessert, double &food_cost, double &tax, double &tip); void exhibit (double &stability); int significant() {    double no_meals, cost_meal, cost_dessert, roomfee, deposit;    double food_cost, tax, tip;    double stability;    getinfo (no_meals, cost_meal, cost_dessert, roomfee, deposit);    calculatecost(no_meals * cost_meal, cost_dessert, food_cost, tax, tip);    exhibit (stability);    go back 0; } void getinfo (double &no_meals, double &cost_meal, double &cost_dessert, double &roomfee, double &deposit) {    cout << "enter the kind of food : ";    cin >> no_meals;    cout << "enter the fee of each meal : ";    cin >> cost_meal; } void calculatecost (double cost_meal, double cost_dessert, double &food_cost, double &tax, double &tip) {    food_cost = cost_meal + cost_dessert;    tax = food_cost * TAXRATE;    tip = food_cost * TIPRATE; } void exhibit (double &stability) {    cout << "Your present day-day stability is: " << fixed << setprecision(2) << stability << endl; }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...