Hi,
I am making a small application of a cash register that add's items,get total amount etc. My add function does not work and neither does the total function. If someone could help me it will be greatly appreciated.
Code:
char itemName;
float itemPrice=0;
float total;
int numberOfItems=0;
int number;
char scanItem;
float scanPrice;
void add(float itemPrice,char itemName);
float getTotal();
float calaverage();
int main(int argc, char *argv[]){
while (1) {
printf("1. Add Item\n");
printf("2. Compute Total\n");
printf("3. Compute Average\n");
printf("4. Compute Change\n");
printf("5. Reset Cash-register\n");
printf("6. Quit\n");
printf("Enter Option: ");
scanf("%d",&number);
if(number==1){
scanf("%f,%c",&scanPrice,&scanItem);
add(scanPrice,scanItem);
//printf("%4f %c",itemPrice,scanItem);
}
else if(number==2){
float totalPrice = getTotal();
printf("%f",&totalPrice);
}
else if(number==4){
printf("you pressed4\n");
}
else if(number==5){
printf("you pressed5\n");
}
else if(number==6){
break;
}
else{
printf("Invalid Option\n");
}
}
}
void add(float aPrice,char aName){
itemPrice = aPrice;
itemName = aName;
total=total+aPrice;
numberOfItems=numberOfItems+1;
}
float getTotal(){
return total;
}
float calaverage(){ total/numberOfItems;}