Down here is a part of my current code (still incomplete). I was trying to assign the amount of cost to *costPtr. But after assigning it, I test the result in the main function to see if I got the right value for my choice, the result appeared to be 0.00001 instead of the value as assigned (299.9 or 349.99 or 999.99). What's wrong? I couldn't find the answer.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
void DisplayApps(char *selectionPtr);
void SetCost(char selection, double *costPtr);
//void PaymentOptions(double *depositPtr, double cost);
//int Compare(double deposit, double choiceCost);
//void Pay(double *depositPtr, double choiceCost);
//void GetChanged(double *depositPtr, double choiceCost);
//void DoItAgain(char *quitPtr);
int main()
{
char selection;
char *selectionPtr;
//double choiceCost;
double *costPtr;
//double *depositPtr;
//char *quitPtr;
printf("Welcome to the App Store\n");
printf("***************************\n\n");
DisplayApps(&selectionPtr);
selection = selectionPtr;
printf("Your choice %c\n", selection);
SetCost(selection, &costPtr);
printf("The cost of this item is %fl\n", costPtr);
return 0;
}
void DisplayApps(char *selectionPtr)
{
printf("-------------------------\n");
printf("HERE ARE THE SLECTIONS\n");
printf("C -- Clown Punching $299.99\n");
printf("V -- Virtual Snow Globe $349.99\n");
printf("R -- Remote PC $999.99\n");
printf("G -- Grocery List Helper $2.99\n");
printf("M -- Mobile Cam Viewer $89.99\n");
printf("\n");
printf("Please enter a selection: ", *selectionPtr);
scanf(" %c", &*selectionPtr);
}
void SetCost(char selection, double *costPtr)
{
double c = 299.99;
double v = 349.99;
double r = 999.99;
double g = 2.99;
double m = 89.99;
if (selection == "C" || selection == "c")
{
*costPtr = c;
}
else if (selection == "V" || selection == "v")
{
*costPtr = v;
}
else if (selection == "R" || selection == "r")
{
*costPtr = r;
}
else if (selection == "G" || selection == "g")
{
*costPtr = g;
}
else if (selection == "M" || selection == "m")
{
*costPtr = m;
}
}