Hello everybody,
I am working on a project for my class and I have come across a couple of issues. Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void DisplayApps(char *appPtr);
void SetCost(char app, double *appCostPtr);
void MoneyChoice(double *depositPtr, double appCost, double Account);
int Compare(double Account, double appCost);
void GetChange(double Account, double appCost);
void AddDeposit(double Deposit, double Account);
void Again(char *quitPtr);
int main()
{
char App='z'; double AppCost=0;; int YayOrNay=0; double Deposit=0; double Account=0; char Quit='z'; int Xfactor=0; //char Quit;
printf("Welcome to The App Store\n");
printf("You currently have $%.2f in your account.\n", Account);
DisplayApps(&App);//displays apps and collects users choice
SetCost(App, &AppCost);//uses users choice to update the cost
Xfactor = Compare(Account, AppCost);//compares the amount in the users account with the cost of the product
if (Xfactor==0)//user does not have enough money, calls following three functions to increase amount in users account
{
do
{
MoneyChoice(&Deposit, AppCost, Account);//shows user options for how much to add to account
AddDeposit(Deposit, Account);//adds the amount user entered into account
YayOrNay = Compare(Account, AppCost);//determines whether or not user still has enough
}
while(YayOrNay==0);//process will cycle through until user has added enough money into account for purchase
}
else
{printf("...");}//user has enough money for purchase, proceed to check out
GetChange(Account, AppCost);//subtracts cost of purchase from users account and updates Account
//Again(&Quit);
return 0;
}
void DisplayApps(char* appPntr)
{
char Selection='h';
do
{
printf("G: Graphing Calculator $14.99\n");
printf("M: Music Downloader $1.99\n");
printf("S: SAT Study Prep $7.99\n");
printf("T: TxtHelp $4.99\n");
printf("A: Astronomy Guide $5.99\n");
printf("Please enter selection: ");
Selection = tolower(Selection);
scanf(" %c", Selection);
}
while(Selection != 'g' || 'm' || 's' || 't' || 'a' );
appPntr = &Selection;
return;
}
void SetCost(char app, double *appCostPtr)
{
char Selection = app; double Cost;
if (Selection=='g')
{
Cost = 14.99;
}
else if (Selection=='m')
{
Cost = 1.99;
}
else if (Selection=='s')
{
Cost=7.99;
}
else if (Selection='t')
{
Cost= 4.99;
}
else if (Selection = 'a')
{
Cost=5.99;
}
appCostPtr = &Cost;
}
void MoneyChoice(double *depositPtr, double appCost, double Account)
{
double DepOption=0; double Cost = appCost; double Selection=0;
do
{
printf("You currently have $%.2f in your account.", Account);
printf("The item you wish to purchase costs $%.2f.", appCost);
printf("Please add a credit towards your account.");
printf("1>> $15.00");
printf("2>> $10.00");
printf("3>> $5.00");
printf("4>> $2.00");
printf("5>> $1.00");
printf("Amount to be added to account: ");
scanf(" %d", Selection);
}
while (Selection != 1 || 2 || 3 || 4 || 5);
if (Selection==1)
{DepOption = 15.00;}
else if (Selection==2)
{DepOption=10.00;}
else if (Selection==3)
{DepOption=5.00;}
else if (Selection==4)
{DepOption=2.00;}
else if (Selection==5)
{DepOption=1.00;}
else
{printf("...");}
depositPtr = &DepOption;
return;
}
int Compare(double Deposit, double appCost)
{
if (Deposit < appCost)
{
return 0;
}
else
{
return 1;
}
}
void AddDeposit (double Account, double Deposit)
{
Account = Account + Deposit;
return;
}
void GetChange(double Account, double appCost)
{
Account = Account - appCost;
}
|
So, when I try to run this program I keep getting the following build error message:
(15): error C2143: syntax error : missing ';' before 'type'
(15): error C2143: syntax error : missing ';' before 'type'
(15): error C2143: syntax error : missing ';' before 'type'
(15): error C2143: syntax error : missing ';' before 'type'
(15): error C2143: syntax error : missing ';' before 'type'
(17): error C2065: 'Account' : undeclared identifier
(23): error C2065: 'Xfactor' : undeclared identifier
(23): error C2065: 'Account' : undeclared identifier
(24): error C2065: 'Xfactor' : undeclared identifier
(28): error C2065: 'Deposit' : undeclared identifier
(28): warning C4133: 'function' : incompatible types - from 'int *' to 'double *'
(28): error C2065: 'Account' : undeclared identifier
(29): error C2065: 'Deposit' : undeclared identifier
(29): error C2065: 'Account' : undeclared identifier
(30): error C2065: 'YayOrNay' : undeclared identifier
(30): error C2065: 'Account' : undeclared identifier
(32): error C2065: 'YayOrNay' : undeclared identifier
(37): error C2065: 'Account' : undeclared identifier
The main issue I am concerned with is the incompatible function warning on line 28. It says int* to double* but I cannot see the int* it is referring to. Also, I do not understand why it is saying that all of those variables are undeclared when I am pretty sure I declared them correctly. I have been trying to fix this problem all weekend with the proj being due tomorrow afternoon. I am running out of time and I hope someone here will be able to assist me! I have tried not to ask so many simple questions anymore and work on them myself (and have been successful at doing so thus far) but I just cannot figure this one out at all. So if anyone doesn't mind sparing a few minutes to look over my code, it really would be greatly appreciated, more so than I ever could express on this forum. Thanks again, everyone.