Greetings Im having trouble with my appstore programming ass
Greetings,
I\'m having trouble with my appstore programming assignment in C. I\'m trying to create appstore program . here is the caviar, i cannot declare the pointers at beginning of the main function. however, i have to you pointers inside the prototype functions or inside the parameters. I\'m having trouble in having the program recognize the pointers inside the prototypes. here is my code. Please help!!
#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS
// Displays the list of apps available
 //prompts for the user’s selection and sets the value of the selection
 void AppMenu(char *appChoicePtr);
//sets the cost of the item based on value stored in purchase
 void GetCost(char appChoice, double *appCostPtr);
//Displays the codes for money input- gets user input amounts
 //compares the int codes and updates the deposit amount
 void MoneyMenu(double *BalancePtr, double appCost);
//compares the amount the user has in deposits to the price of item selected.
 //It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
 int Enough(double balance, double appCost);
//uses MoneyMenu function to display and collect dollar amounts from the user
 //uses CheckMoney function to keep comparing the added deposited amount to the item cost.
 void GetMoney(double *balancePtr, double appCost);
//calculates the amount of leftover from your deposits
 void GetChange(double *balancePtr, double appCost);
//Asks the user if they want another app
 void Again(char *quitPtr);
int main()
 {
    char quit;
    char appChoice = \' \';
    double appCost;
    double balance = 0;
    printf(\"###### Welcome to the App Store ######\");
    //call Quit
    Again(&quit);
    //initialize while loop
    do{
        printf(\"\ \ -----------------------------------\");
        //call menu
        AppMenu(&appChoicePtr);
        printf(\"You selected: %c\", appChoicePtr);
        //call getcost
        GetCost(appChoice, &appCostPtr);
        printf(\"\ That item costs $%.2f\", appCostPtr);
        //call getmoney
        GetMoney(&balancePtr, appCost);
        printf(\"\ Your current balance is $%.2f\", balancePtr);
        //call getchange
        GetChange(&balancePtr, appCost);
        Again(&quit);
   } while (quit != \'N\'&&quit != \'n\');
    //end while loop
    printf(\"\ \ Thank You!, Good Bye\ \");
    return 0;
 }
 void AppMenu(char *appChoicePtr)
 {
    printf(\"\ \ _____PLEASE MAKE A SELECTION_____\ \ \");
    printf(\" \ G -- Graphic Calculator $14.95\");
    printf(\" \ M -- Music Downloader $2.95\");
    printf(\" \ C -- C programming guide $7.95\");
    printf(\" \ T -- TxtToVoice $4.95\");
    printf(\" \ A -- Astronomy Guide $5.95\ \ >>>\");
    scanf_s(\" %c\", appChoicePtr);
 }
 void MoneyMenu(double *BalancePtr, double appCost)
 {
    int input = 1;
    printf(\"\ Please credit your money by making a selection:\ -- 20 $20.00\ -- 10 $10.00\ --- 5 $5.00\ --- 1 $1.00\ \ Deposit Selection: \");
    scanf_s(\" %d\", &input);
    printf(\"\ You have entered: %d\", input);
    //display money choices
    if (input == 20)
    {
        *BalancePtr += 20.0;
    }
    else if (input == 10)
    {
        *BalancePtr += 10.0;
    }
    else if (input == 5)
    {
        *BalancePtr += 5.0;
    }
    else if (input == 1)
    {
        *BalancePtr += 1.0;
    }
 }
 void GetCost(char appChoice, double *appCostPtr)
 {
    //condition to update the selection made by the user
    if (appChoice == \'M\' || appChoice == \'m\')
    {
        *appCostPtr = 2.95;
    }
    else if (appChoice == \'G\' || appChoice == \'g\')
    {
        *appCostPtr = 14.95;
    }
    else if (appChoice == \'C\' || appChoice == \'c\')
    {
        *appCostPtr = 7.95;
    }
    else if (appChoice == \'T\' || appChoice == \'t\')
    {
        *appCostPtr = 4.95;
    }
    else if (appChoice == \'A\' || appChoice == \'a\')
    {
        *appCostPtr = 5.95;
    }
 }
 void GetMoney(double *balancePtr, double appCost)
 {
    // call money menu
    MoneyMenu(*BalancePtr, appCost);
    //call check money
    CheckMoney(*deposits, item_cost);
 }
 int Enough(double balance, double appCost)
 {
    //condition to check if money is enough to cover purchase
    if (balance >= appCost)
    {
        return 1;
    }
    else if (balance<appCost)
    {
        printf(\"\ Insufficient funds, you need to add more money\");
        return balance;
    }
 }
 void GetChange(double *balancePtr, double appCost)
 {
    double change = 0;
   //calculate change left over from transaction
    change = *balancePtr - appCost;
    printf(\"\ You have...$%.2f\", change);
 }
void Again(char *quitPtr)
 {
    printf(\"\ \ Would you like to buy an app Y/N?: \");
    scanf(\" %c\", *quitPtr);
 }
Solution
Hi,
You need to assign variables inside the main function,and then using (&) assign the address of the variable.I compiled your code and fix the bugs , Wherever required inside main function.
Like, you have to declare local variables ex:
char q;
 double d;
 double b;
AppMenu(&q);// Like this you should call your Appmenu Method,
 printf(\"You selected: %c\", &q);
 //call getcost
 GetCost(appChoice, &d);
GetCost(appChoice, &d); Call Getcost function Like this
 printf(\"\ That item costs $%.2f\", d);
 //call getmoney
 GetMoney(&b, appCost);//Call getMoney Function like this
 printf(\"\ Your current balance is $%.2f\", b);
int main()
 {
 char quit;
 char appChoice = \' \';
 double appCost;
 double balance = 0;
 char q;
 double d;
 double b;
 printf(\"###### Welcome to the App Store ######\");
//call Quit
 Again(&quit);
 //initialize while loop
 do{
   
 printf(\"\ \ -----------------------------------\");
 //call menu
 AppMenu(&q);
 printf(\"You selected: %c\", &q);
 //call getcost
 GetCost(appChoice, &d);
 printf(\"\ That item costs $%.2f\", d);
 //call getmoney
 GetMoney(&b, appCost);
 printf(\"\ Your current balance is $%.2f\", b);
 //call getchange
 GetChange(&b, appCost);
 Again(&quit);
 } while (quit != \'N\'&&quit != \'n\');
 //end while loop
 printf(\"\ \ Thank You!, Good Bye\ \");
 return 0;
 }
 void AppMenu(char *appChoicePtr)
 {
 printf(\"\ \ _____PLEASE MAKE A SELECTION_____\ \ \");
 printf(\" \ G -- Graphic Calculator $14.95\");
 printf(\" \ M -- Music Downloader $2.95\");
 printf(\" \ C -- C programming guide $7.95\");
 printf(\" \ T -- TxtToVoice $4.95\");
 printf(\" \ A -- Astronomy Guide $5.95\ \ >>>\");
 scanf_s(\" %c\", appChoicePtr);
 }
 void MoneyMenu(double *BalancePtr, double appCost)
 {
 int input = 1;
 printf(\"\ Please credit your money by making a selection:\ -- 20 $20.00\ -- 10 $10.00\ --- 5 $5.00\ --- 1 $1.00\ \ Deposit Selection: \");
 scanf_s(\" %d\", &input);
 printf(\"\ You have entered: %d\", input);
 //display money choices
 if (input == 20)
 {
 *BalancePtr += 20.0;
 }
 else if (input == 10)
 {
 *BalancePtr += 10.0;
 }
 else if (input == 5)
 {
 *BalancePtr += 5.0;
 }
 else if (input == 1)
 {
 *BalancePtr += 1.0;
 }
 }
 void GetCost(char appChoice, double *appCostPtr)
 {
 //condition to update the selection made by the user
 if (appChoice == \'M\' || appChoice == \'m\')
 {
 *appCostPtr = 2.95;
 }
 else if (appChoice == \'G\' || appChoice == \'g\')
 {
 *appCostPtr = 14.95;
 }
 else if (appChoice == \'C\' || appChoice == \'c\')
 {
 *appCostPtr = 7.95;
 }
 else if (appChoice == \'T\' || appChoice == \'t\')
 {
 *appCostPtr = 4.95;
 }
 else if (appChoice == \'A\' || appChoice == \'a\')
 {
 *appCostPtr = 5.95;
 }
 }
 void GetMoney(double *balancePtr, double appCost)
 {
 // call money menu
 MoneyMenu(*balancePtr, appCost);
 //call check money
 CheckMoney(*deposits, item_cost);
 }
 int Enough(double balance, double appCost)
 {
 //condition to check if money is enough to cover purchase
 if (balance >= appCost)
 {
 return 1;
 }
 else if (balance<appCost)
 {
 printf(\"\ Insufficient funds, you need to add more money\");
 return balance;
 }
 }
 void GetChange(double *balancePtr, double appCost)
 {
 double change = 0;
 //calculate change left over from transaction
 change = *balancePtr - appCost;
 printf(\"\ You have...$%.2f\", change);
 }
 void Again(char *quitPtr)
 {
 printf(\"\ \ Would you like to buy an app Y/N?: \");
 scanf(\" %c\", *quitPtr);
 }





