|
Newbie
Join Date: Nov 2004
Posts: 15
Rep Power: 0 
|
Dear all,
Thanks for help these days.I tried to rewrite the program part by part,step by step again.Although finally error is reduced,but they still exists.And I am here to heop if your guys can help me to correct it,and if possible,help me to check if there's any undetected error from my source as well.
#include <stdio.h>
#include <math.h>
/*initilize pointed values into 0*/
int c5=0;
int c2=0;
int c1=0;
int a_paid=1;
int a_due=1;
int dollars;
int change;
/*assiging initialize value to the pointers*/
paid=&a_paid;
due=&a_due;
/*function initialization*/
int getData(int *paid,int *due);
/*function initialization*/
void dispense(int change,int *dollars,int *c50,int *c20,int *c10);
int main()
{
/*repeat the loop until user enters both 0*/
do {
/*prompt user to enter 2 numbers*/
getData (&paid,&due);
/*while the pointed values a_due(pointed by *due) and a_paid(pointed by *paid) not equals to 0 then do*/
while (&due!=0 && &paid!=0){
/*calculate the change and the number of the respected pointers(cents)*/
dispense (&a_paid,&a_due);
printf ("\namount due:%d",due);
printf ("amount paid:%d",paid);
printf ("and thus change=%d",dollars);
/*display specific output to user depending if the pointed values(cents) are 0*/
if (change<5) {
if (c2==0) {
printf ("You are suggested to give him/her %d 10-cents coin(s)",c1);}
if (c1==0) {
printf ("You are suggested to give him/her %d 20-cents coin(s)",c2);}
else
printf ("You are suggested to give him/her %d 10-cents coin(s) %d 20-cents coin(s)",c1,c2);}
else if (change>5) {
if (c2==0) {
printf ("You are suggested to give him/her %d 10-cents coin(s) %d 50-cents coin(s)",c1,c5);}
if (c1==0) {
printf ("You are suggested to give him/her %d 20-cents coin(s) %d 50-cents coin(s) ",c2,c5);}
else
printf ("You are suggested to give him/her %d 10-cents coin(s) %d 20-cents coin(s) %d 50-cents coin(s)",c1,c2,c5);}
else if (change==5) {
printf ("You are suggested to give him/her %d 50-cents coin(s)",c5);}
}
} while (getData (&paid,&due)==1);
}
int getData (int *paid,int *due){
printf ("\nThe amount-paid and amount-due should be entered in cents(integer)");
/*repeat until due<0 or paid<due*/
do {
printf ("\nTo terimate the program,enter 0 for both values.");
printf ("\nEnter the amount-paid abd amount-due please:");
scanf ("%d %d",&a_paid,&a_due); } while (*due<0||*paid<*due);
if (*paid==0&&*due==0){
return 0;}
else {
return 1;}
}
void dispense (int change,int *dollars,int *c50,int *c20,int *c10){
/*By substract the paid and due and divide it by 10 to obtain the actual change,and round it up to the nearest 10*/
change=(*paid-*due);
dollars=&change;
rounded=round(change);
/*while the change is in range do the followings*/
while (change>=10&&change<=90) {
switch (rounded){
case '10':c1+=1;
break;
case '20':c2+=1;
break;
case '30':c1+=1;
c2+=1;
break;
case '40':c2+=2;
break;
case '50':c5+=1;
break;
case '60':c1+=1;
c5+=1;
break;
case '70':c2+=1;
c5+=1;
break;
case '80':c1+=1;
c2+=1;
c5+=1;
break;
case '90':c2+=2;
c5+=1;
break;
default:printf ("\nCheck your input!");
printf("\nEnter the amount paid and amount-due please:"); }
}
}
Detected Errors:
warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'int *'
A:\01.c(14) : warning C4047: 'initializing' : 'int ' differs in levels of indirection from 'int *'
A:\01.c(31) : warning C4047: 'function' : 'int ' differs in levels of indirection from 'int *'
A:\01.c(31) : warning C4024: 'dispense' : different types for formal and actual parameter 1
A:\01.c(31) : error C2198: 'dispense' : too few actual parameters
A:\01.c(81) warning C4013: 'roundoff' undefined; assuming extern returning int /*I don't know what is the function that can round up 11-->10,15-->20*/
A:\01.c(79) : error C2100: illegal indirection
A:\01.c(79) : error C2100: illegal indirection
|