could someone to please go through my code and find out why it only outputs 0.00
ID: 671424 • Letter: C
Question
could someone to please go through my code and find out why it only outputs 0.00 and not the actual cost of the flowers. I know the calculation logic works because of a perivace version i had that ran and out put the cost, but i added
typedef enum {No_Error = 1, Unavailable_Selection, Invalid_Argument, Null_Pointer} Error;
and now it wont work. if out can help you are the best, and thanks!!
/* 1. Insert the required items in the other 2 enumerated types*/
typedef enum { RED = 1, WHITE } Color;
typedef enum { roses = 1, daises, lilies} Flower;
typedef enum {bouq = 1,vase} Arrangement;
typedef enum {No_Error = 1, Unavailable_Selection, Invalid_Argument, Null_Pointer} Error;
/*Function prototype */
int getCost(double *cost, Flower flower, Color color, Arrangement arr, Error error);
int main (void) {
//You can declare variables that hold your enums just like regular variables
Flower flower;
Color color;
Arrangement arr;
Error error;
double cost;
/* 3. Declare the other required variable(s)*/
printf(" Types of flowers ");
printf("1. Roses ");
printf("2. Lilies ");
printf("3. Daises ");
printf("Please enter the item number for your choice: ");
scanf("%d", &flower);
printf(" Color choices ");
printf("1. Red ");
printf("2. White ");
printf("Please enter the item number for your choice: ");
scanf("%d", &color);
printf(" Arrangements ");
printf("1. Bouquet ");
printf("2. Vase ");
printf("Please enter the item number for your choice: ");
scanf("%d", &arr);
/*4 complete the function call and print the cost*/
error = getCost(&cost, flower,color,arr, error);
if (error == Unavailable_Selection)
{
printf("That flower is currently unavailavle, sorry./n");
}
else if (flower < 1 || flower > 3 ||(color < 1 || color > 2 ||(arr < 1 || arr > 2)))
{
printf("That input is not avaliable. ");
}
else
{
printf("The total is %.2lf ",cost);
}
}
/* 2. Implement the function get_cost*/
int getCost(double *cost, Flower flower, Color color, Arrangement arr, Error error){
double total = 0;
Error errorchecker;
if (flower == 1)
{
*cost = 30;
if(color == 2)
*cost = *cost+10;
if(arr ==2)
*cost = *cost+10;
}
else if (flower == 2)
{
*cost = 20;
if(color == 1)
*cost = *cost+5;
if(arr ==2)
*cost = *cost+10;
}
else if (flower == 3)
{
*cost = 45;
if(color == 1)
*cost = *cost+5;
if(arr ==2)
*cost = *cost+10;
}
*cost = total;
if(flower == 2 && color == 1)
error = Unavailable_Selection;
else total = 0;
return error;
}
Explanation / Answer
/* 1. Insert the required items in the other 2 enumerated types*/
typedef enum { RED = 1, WHITE } Color;
typedef enum { roses = 1, daises, lilies} Flower;
typedef enum {bouq = 1,vase} Arrangement;
typedef enum {No_Error = 1, Unavailable_Selection, Invalid_Argument, Null_Pointer} Error;
/*Function prototype */
int getCost(double *cost, Flower flower, Color color, Arrangement arr, Error error);
int main (void) {
//You can declare variables that hold your enums just like regular variables
Flower flower;
Color color;
Arrangement arr;
Error error;
double cost;
/* 3. Declare the other required variable(s)*/
printf(" Types of flowers ");
printf("1. Roses ");
printf("2. Lilies ");
printf("3. Daises ");
printf("Please enter the item number for your choice: ");
scanf("%d", &flower);
printf(" Color choices ");
printf("1. Red ");
printf("2. White ");
printf("Please enter the item number for your choice: ");
scanf("%d", &color);
printf(" Arrangements ");
printf("1. Bouquet ");
printf("2. Vase ");
printf("Please enter the item number for your choice: ");
scanf("%d", &arr);
/*4 complete the function call and print the cost*/
error = getCost(&cost, flower,color,arr, error);
if (error == Unavailable_Selection)
{
printf("That flower is currently unavailavle, sorry./n");
}
else if (flower < 1 || flower > 3 ||(color < 1 || color > 2 ||(arr < 1 || arr > 2)))
{
printf("That input is not avaliable. ");
}
else
{
printf("The total is %.2lf ",cost);
}
}
/* 2. Implement the function get_cost*/
int getCost(double *cost, Flower flower, Color color, Arrangement arr, Error error){
int total;
Error errorchecker;
if (flower == 1)
{
*cost = 30;
if(color == 2)
*cost = *cost+10;
if(arr ==2)
*cost = *cost+10;
}
else if (flower == 2)
{
*cost = 20;
if(color == 1)
*cost = *cost+5;
if(arr ==2)
*cost = *cost+10;
}
else if (flower == 3)
{
*cost = 45;
if(color == 1)
*cost = *cost+5;
if(arr ==2)
*cost = *cost+10;
}
if(flower == 2 && color == 1)
error = Unavailable_Selection;
else total = 0;
return error;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.