Concerning C++ calculations using printf

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Concerning C++ calculations using printf

 
0
  #11
Aug 6th, 2007
Thanks for the help. I was able to get the calculations in the program right. The old coding I had for it doesnt really work like it did before. Basically I'm trying to have it where the numbers I put in show an error if the number entered is greater than 999 and also show an error if it is a non number aswell. Also trying to see how I can make the information in yearly show only when I type in yearly or "Y" and the information for daily only show when I type in daily or "D". This is the current code I have atm.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

void PrintAStarLine(void);
void GetInput(void);
void Tickets(void);



float price( const float item ){
int piece = 0;
char newline2;
scanf( "%d%c", &piece, &newline2 );
return item * piece;
}

char newline;
char customerName[30];
char tickettype[];
char TicketNumber[] = "D, d";

int main( void )
{

PrintAStarLine();

printf(" Home Aquarium Data Entry \n");
printf("\n\n");

PrintAStarLine();

GetInput();

Tickets();





const float DChild = 1.50;
float DailyChild = 0.00;

const float YChild = 5.50;
float YearlyChild = 0.00;

float TotalChild;

const float DAdult = 2.00;
float DailyAdult = 0.00;

const float YAdult = 6.50;
float YearlyAdult = 0.00;

float TotalAdult;

const float DSenior = 1.25;
float DailySenior = 0.00;

const float YSenior = 3.75;
float YearlySenior = 0.00;

float TotalSenior;






printf("#of Children for daily tickets: " );
fflush( stdout );
DailyChild = price( DChild );
printf("\n\n");

printf("#of Children for yearly tickets: " );
fflush( stdout );
YearlyChild = price( YChild );
printf("\n\n");

printf("#of Adults for daily tickets: " );
fflush( stdout );
DailyAdult = price( DAdult );
printf("\n\n");

printf("#of Adults for yearly tickets: " );
fflush( stdout );
YearlyAdult = price( YAdult );
printf("\n\n");

printf("#of Seniors for daily tickets: " );
fflush( stdout );
DailySenior = price( DSenior );
printf("\n\n");

printf("#of Seniors for yearly tickets: " );
fflush( stdout );
YearlySenior = price( YSenior );
system("pause");
printf("\n\n\n");

TotalChild = (DailyChild + YearlyChild);
TotalAdult = (DailyAdult + YearlyAdult);
TotalSenior = (DailySenior + YearlySenior);




printf( "Children Total Cost: $%6.2f\n", TotalChild );
printf("\n");
printf( "Adult Total Cost: $%6.2f\n", TotalAdult );
printf("\n");
printf( "Senior Total Cost: $%6.2f\n", TotalSenior );
printf("\n");


return 0;
}

void PrintAStarLine(void)

{

printf("**************************************************************************** \n");
printf("\n\n");

return;

}

void GetInput(void)
{



printf("Customer Name (First Middle Last): ");
scanf( "%[^\n]%c", customerName, &newline );
printf("\n\n\n");

return;
}

void Tickets(void)
{

printf("\n\nType of ticket (Daily(D) or Yearly(Y): ");
scanf(" %s", &TicketNumber);


if(strcmp(TicketNumber,"D")==0)
{
printf("#of Children for daily tickets: " ); ;
}
else if(strcmp(TicketNumber,"d")==0)
{
;
}
else if(strcmp(TicketNumber,"Daily")==0)
{
;
}
else if(strcmp(TicketNumber,"daily")==0)
{
;
}
else if(strcmp(TicketNumber,"Y")==0)
{
;
}
else if(strcmp(TicketNumber,"y")==0)
{
;
}
else if(strcmp(TicketNumber,"Yearly")==0)
{
;
}
else if(strcmp(TicketNumber,"yearly")==0)
{
;
}
else
{
printf("\n Incorrect Ticket Number Entered, please try again! \n");
printf("\n");
Tickets();
}
printf("\n");
return;
}
Last edited by NycNessyness; Aug 6th, 2007 at 4:51 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Concerning C++ calculations using printf

 
0
  #12
Aug 6th, 2007
Remember these?
Last edited by Ancient Dragon : 1 Day Ago at 22:05. Reason: add code tags
Last edited by Ancient Dragon : 1 Day Ago at 05:02. Reason: add code tags -- please start using them

Or what about this
http://www.daniweb.com/forums/announcement118-3.html

Not to mention the watermark at the back of the edit window.

If all these escape your attention, then give up programming.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Concerning C++ calculations using printf

 
0
  #13
Aug 6th, 2007
Next time you post your code you need to write those square brackets, or highlight all your code and click in the # symbol.

[
CODE=C] Your code inside here ...[/CODE]
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Concerning C++ calculations using printf

 
0
  #14
Aug 6th, 2007
Oh sorry about that guys. I will do it from now on. As far as my code goes I'm almost done with it. The last problem I have is my calculation. Its currenty messed up because I'm trying different methods by trial and error. What I'm trying to do is make it so that when a ticket is purchased for a child that is accomapanied by 2 or more adults or if accompanied by 3 or more seniors they get 10 percent off of the total purchase. If I can an example like Aia did for me earlier I think I'll be able to finish this off. Thanks again guys for the help. You've helped me more than you can imagine, because I'm learning this online so it's kind of difficult.

  1. #include <string.h>
  2. #include <iostream>
  3.  
  4. void PrintAStarLine(void);
  5. void GetInput(void);
  6. void Tickets(void);
  7. void AskQuestion(void);
  8.  
  9.  
  10.  
  11. float price( const float item ){
  12. int piece = 0;
  13. char newline2;
  14. scanf( "%d%c", &piece, &newline2 );
  15. return item * piece;
  16. }
  17.  
  18.  
  19. char newline;
  20. char customerName[30];
  21. char tickettype[];
  22. char TicketNumber[] = "D, d";
  23. char NumberName[10];
  24. char Underlines[10];
  25. char aQuestion;
  26.  
  27.  
  28. int main( void )
  29. {
  30.  
  31. PrintAStarLine();
  32.  
  33. printf(" Home Aquarium Data Entry \n");
  34. printf("\n\n");
  35.  
  36. PrintAStarLine();
  37.  
  38.  
  39. GetInput();
  40.  
  41.  
  42. Tickets();
  43.  
  44.  
  45. const float DChild = 1.50;
  46. float DailyChild = 0.00;
  47.  
  48. const float YChild = 5.50;
  49. float YearlyChild = 0.00;
  50.  
  51. float TotalChild;
  52.  
  53. const float DAdult = 2.00;
  54. float DailyAdult = 0.00;
  55.  
  56. const float YAdult = 6.50;
  57. float YearlyAdult = 0.00;
  58.  
  59. float TotalAdult;
  60.  
  61. const float DSenior = 1.25;
  62. float DailySenior = 0.00;
  63.  
  64. const float YSenior = 3.75;
  65. float YearlySenior = 0.00;
  66.  
  67. float TotalSenior;
  68.  
  69.  
  70. float TotalCost;
  71.  
  72. float LessDiscount;
  73.  
  74. float TotalDiscount;
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. printf("#of Children for daily tickets: " );
  82. fflush( stdout );
  83. DailyChild = price( DChild );
  84. printf("\n\n");
  85.  
  86. printf("#of Children for yearly tickets: " );
  87. fflush( stdout );
  88. YearlyChild = price( YChild );
  89. printf("\n\n");
  90.  
  91. printf("#of Adults for daily tickets: " );
  92. fflush( stdout );
  93. DailyAdult = price( DAdult );
  94. printf("\n\n");
  95.  
  96. printf("#of Adults for yearly tickets: " );
  97. fflush( stdout );
  98. YearlyAdult = price( YAdult );
  99. printf("\n\n");
  100.  
  101. printf("#of Seniors for daily tickets: " );
  102. fflush( stdout );
  103. DailySenior = price( DSenior );
  104. printf("\n\n");
  105.  
  106. printf("#of Seniors for yearly tickets: " );
  107. fflush( stdout );
  108. YearlySenior = price( YSenior );
  109. system("pause");
  110. printf("\n\n\n");
  111.  
  112.  
  113. system("cls");
  114.  
  115. PrintAStarLine();
  116. printf(" Home Aquarium Contract \n");
  117. printf("\n\n");
  118. PrintAStarLine();
  119.  
  120. printf("CustomerName: %s \n", customerName);
  121.  
  122.  
  123.  
  124.  
  125. if(strcmp(TicketNumber,"D")==0)
  126. {
  127. printf("Type of ticket: Daily \n", TicketNumber);
  128. printf("\n\n");
  129. }
  130. else if(strcmp(TicketNumber,"d")==0)
  131. {
  132. printf("Type of ticket: Daily \n", TicketNumber);
  133. printf("\n\n");
  134. }
  135. else if(strcmp(TicketNumber,"Daily")==0)
  136. {
  137. printf("Type of ticket: Daily \n", TicketNumber);
  138. printf("\n\n");
  139. }
  140. else if(strcmp(TicketNumber,"daily")==0)
  141. {
  142. printf("Type of ticket: Daily \n", TicketNumber);
  143. printf("\n\n");
  144. }
  145. else if (TicketNumber == "Y")
  146. {
  147. printf("Type of ticket: Yearly \n", TicketNumber);
  148. printf("\n\n");
  149. }
  150. else if(strcmp(TicketNumber,"y")==0)
  151. {
  152. printf("Type of ticket: Yearly \n", TicketNumber);
  153. printf("\n\n");
  154. }
  155. else if(strcmp(TicketNumber,"Yearly")==0)
  156. {
  157. printf("Type of ticket: Yearly \n", TicketNumber);
  158. printf("\n\n");
  159. }
  160. else if(strcmp(TicketNumber,"yearly")==0)
  161. {
  162. printf("Type of ticket: Yearly \n", TicketNumber);
  163. printf("\n\n");
  164. }
  165.  
  166.  
  167.  
  168.  
  169.  
  170. if (DailyAdult >= 2)
  171. TotalChild = TotalCost * .10;
  172. else if (YearlyAdult >= 2)
  173. TotalChild = TotalCost * .10;
  174. else if (DailySenior >= 3)
  175. TotalChild = TotalCost * .10;
  176. else if (YearlySenior >=3)
  177. TotalChild = TotalCost * .10;
  178. else
  179.  
  180.  
  181.  
  182.  
  183.  
  184. TotalChild = (DailyChild + YearlyChild);
  185. TotalAdult = (DailyAdult + YearlyAdult);
  186. TotalSenior = (DailySenior + YearlySenior);
  187. TotalCost = (TotalAdult) + (TotalSenior) + (TotalChild);
  188. LessDiscount = (TotalCost);
  189. TotalDiscount = (TotalCost) - (LessDiscount);
  190.  
  191.  
  192. system("pause");
  193. printf(" Charge Number %s \n", NumberName);
  194. printf("\n\n");
  195. printf( "Child: $%6.2f\n", TotalChild );
  196. printf("\n");
  197. printf( "Adult: $%6.2f\n", TotalAdult );
  198. printf("\n");
  199. printf( "Senior: $%6.2f\n", TotalSenior );
  200. printf("\n");
  201. printf(" ======= ======= %s \n", Underlines);
  202. printf("\n\n");
  203. printf( "Total: $%6.2f\n", TotalCost );
  204. printf("\n");
  205. printf( "Less Discount: $%6.2f\n", LessDiscount );
  206. printf("\n");
  207. printf( "Total After Discount: $%6.2f\n", TotalDiscount );
  208. printf("\n");
  209.  
  210.  
  211.  
  212. aQuestion = 'N';
  213. while ((aQuestion != 'Y') && (aQuestion != 'y'))
  214. AskQuestion();
  215.  
  216.  
  217. system("cls");
  218.  
  219. return 0;
  220. }
  221.  
  222. void PrintAStarLine(void)
  223.  
  224. {
  225.  
  226. printf("******************************************************************************** \n");
  227. printf("\n\n");
  228.  
  229. return;
  230.  
  231. }
  232.  
  233. void GetInput(void)
  234. {
  235.  
  236.  
  237.  
  238. printf("Customer Name (First Middle Last): ");
  239. scanf( "%[^\n]%c", customerName, &newline );
  240. printf("\n\n\n");
  241.  
  242. return;
  243. }
  244.  
  245. void Tickets(void)
  246. {
  247.  
  248. printf("\n\nType of ticket (Daily(D) or Yearly(Y): ");
  249. scanf(" %s", &TicketNumber);
  250.  
  251.  
  252. if(strcmp(TicketNumber,"D")==0)
  253. {
  254.  
  255. }
  256. else if(strcmp(TicketNumber,"d")==0)
  257. {
  258. ;
  259. }
  260. else if(strcmp(TicketNumber,"Daily")==0)
  261. {
  262. ;
  263. }
  264. else if(strcmp(TicketNumber,"daily")==0)
  265. {
  266. ;
  267. }
  268. else if(strcmp(TicketNumber,"Y")==0)
  269. {
  270. ;
  271. }
  272. else if(strcmp(TicketNumber,"y")==0)
  273. {
  274. ;
  275. }
  276. else if(strcmp(TicketNumber,"Yearly")==0)
  277. {
  278. ;
  279. }
  280. else if(strcmp(TicketNumber,"yearly")==0)
  281. {
  282. ;
  283. }
  284. else
  285. {
  286. printf("\n Incorrect Ticket Number Entered, please try again! \n");
  287. printf("\n");
  288. Tickets();
  289. }
  290. printf("\n");
  291. return;
  292. }
  293.  
  294. void AskQuestion(void)
  295. {
  296. printf("\n\nAre we done for the day? (Y/N)");
  297. scanf(" %c", &aQuestion);
  298. fflush(stdin);
  299.  
  300.  
  301. return ;
  302. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Concerning C++ calculations using printf

 
0
  #15
Aug 6th, 2007
What I'm trying to do is make it so that when a ticket is purchased for a child that is accomapanied by 2 or more adults or if accompanied by 3 or more seniors they get 10 percent off of the total purchase.
Do you realize that you only have to check if a child is accompanied by two adults to recieve the discount? I know that seniors might be another "species of their own", but they are, also, adults.

Your code is pretty hard to read, right now.
It is custumary to declare the functions after the closing bracket of main and declare the prototypes of those functions before main.
Right now you have a function at the top and the rest at the bottom.

#include <iostream>
is for C++. C should be <stdio.h>

A few lines of comments indicating what expressions do, would help you also. Specially functions.

Bonus example:

  1. /*
  2.  * line.c
  3.  * Shows how to use an independent function to print a line of
  4.  * stars and newlines.
  5.  */
  6. #include <stdio.h>
  7.  
  8. void PrintAStarLine( int star, int newline ); /* prototype */
  9.  
  10. int main( void )
  11. {
  12. PrintAStarLine( 80, 4 ); /* give it any arguments you want */
  13. getchar();
  14. return 0;
  15. }
  16.  
  17. /*
  18.  * PrintAStarLine: Prints a line of star characters
  19.  * parameters: a int for the amount of char stars, a int for amount of newlines
  20.  * return void.
  21.  */
  22. void PrintAStarLine( int star, int newline )
  23. {
  24. while( star-- )
  25. {
  26. putchar( '*' );
  27. }
  28. while( newline-- )
  29. {
  30. putchar( '\n' );
  31. }
  32. }
Last edited by Aia; Aug 6th, 2007 at 10:47 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Concerning C++ calculations using printf

 
0
  #16
Aug 7th, 2007
I was able to do the calculations and did the labeling of my code. I'm pretty much done with the program but still having a bit of difficulty with displaying data. The only error I have atm now is trying to get the program to display the number i entered for each ticket alongside the ticket cost. May someone be kind enough to give me a clue as to how I can do this.


  1. /*+*+*+*+*+*+*+* Preprocessor Directives *+*+*+*+*+*+*+*/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. /*+*+*+*+*+*+*+* Function Prototypes *+*+*+*+*+*+*+*/
  8.  
  9. void PrintAStarLine(void);
  10. void GetInput(void);
  11. void Tickets(void);
  12. void DailyTickets(void);
  13. void YearlyTickets(void);
  14. void NewPageDisplay(void);
  15. void SecondPageDisplay(void);
  16. void Calculations(void);
  17. void AskQuestion(void);
  18.  
  19. /*+*+*+*+*+*+*+* Variables *+*+*+*+*+*+*+*/
  20.  
  21.  
  22. float price( const float item ){
  23. int piece = 0;
  24. char newline2;
  25. scanf( "%d%c", &piece, &newline2 );
  26. return item * piece;
  27. }
  28.  
  29.  
  30. char newline;
  31. char customerName[30];
  32. char tickettype[];
  33. char TicketNumber[] = "D, d";
  34. char NumberName[10];
  35. char Underlines[10];
  36. char aQuestion;
  37. char TotalIncome[10];
  38.  
  39.  
  40.  
  41. const float DChild = 1.50;
  42. float DailyChild = 0.00;
  43. const float YChild = 5.50;
  44. float YearlyChild = 0.00;
  45. float TotalChild;
  46.  
  47. const float DAdult = 2.00;
  48. float DailyAdult = 0.00;
  49. const float YAdult = 6.50;
  50. float YearlyAdult = 0.00;
  51. float TotalAdult;
  52.  
  53. const float DSenior = 1.25;
  54. float DailySenior = 0.00;
  55. const float YSenior = 3.75;
  56. float YearlySenior = 0.00;
  57. float TotalSenior;
  58.  
  59.  
  60. float TotalCost;
  61.  
  62. float LessDiscount;
  63.  
  64. float TotalDiscount;
  65.  
  66.  
  67. /*+*+*+*+*+*+*+*^ The Main Module ^*+*+*+*+*+*+*+*/
  68.  
  69.  
  70. int main( void )
  71. {
  72.  
  73. PrintAStarLine();
  74.  
  75. printf(" Home Aquarium Data Entry \n");
  76. printf("\n\n");
  77.  
  78. PrintAStarLine();
  79.  
  80.  
  81. GetInput();
  82.  
  83. Tickets();
  84.  
  85. Calculations();
  86.  
  87. NewPageDisplay();
  88.  
  89.  
  90.  
  91.  
  92. aQuestion = 'N'; /* It will loop until user enter Y */
  93. while ((aQuestion != 'Y') && (aQuestion != 'y')) /*sets value to go into loop the first time */
  94.  
  95. AskQuestion();
  96.  
  97.  
  98.  
  99. system("cls");
  100.  
  101. SecondPageDisplay();
  102.  
  103. return 0;
  104. }
  105.  
  106. /*+*+*+*+*+*+*+* Avoids making the program look real plain *+*+*+*+*+*+*+*/
  107.  
  108. void PrintAStarLine(void)
  109.  
  110. {
  111.  
  112. printf("******************************************************************************** \n");
  113. printf("\n\n");
  114.  
  115. return;
  116.  
  117. }
  118.  
  119. /*+*+*+*+*+*+*+* Asks The User for their name *+*+*+*+*+*+*+*/
  120.  
  121. void GetInput(void)
  122. {
  123.  
  124.  
  125.  
  126. printf("Customer Name (First Middle Last): ");
  127. scanf( "%[^\n]%c", customerName, &newline );
  128. printf("\n\n\n");
  129.  
  130. return;
  131. }
  132.  
  133. /*+*+*+*+*+*+*+* Asks The User what ticket type they want *+*+*+*+*+*+*+*/
  134.  
  135. void Tickets(void)
  136. {
  137.  
  138. printf("\n\nType of ticket (Daily(D) or Yearly(Y): ");
  139. scanf(" %s", &TicketNumber);
  140.  
  141.  
  142. if(strcmp(TicketNumber,"D")==0)
  143. {
  144. DailyTickets();
  145. }
  146. else if(strcmp(TicketNumber,"d")==0)
  147. {
  148. DailyTickets();
  149. }
  150. else if(strcmp(TicketNumber,"Daily")==0)
  151. {
  152. DailyTickets();
  153. }
  154. else if(strcmp(TicketNumber,"daily")==0)
  155. {
  156. DailyTickets();
  157. }
  158. else if(strcmp(TicketNumber,"Y")==0)
  159. {
  160. YearlyTickets();
  161. }
  162. else if(strcmp(TicketNumber,"y")==0)
  163. {
  164. YearlyTickets();
  165. }
  166. else if(strcmp(TicketNumber,"Yearly")==0)
  167. {
  168. YearlyTickets();
  169. }
  170. else if(strcmp(TicketNumber,"yearly")==0)
  171. {
  172. YearlyTickets();
  173. }
  174. else
  175. {
  176. printf("\n Incorrect Ticket Number Entered, please try again! \n");
  177. printf("\n");
  178. Tickets();
  179. }
  180. printf("\n");
  181. return;
  182. }
  183.  
  184. /*+*+*+*+*+*+*+* Allows the user to enter daily tickets *+*+*+*+*+*+*+*/
  185.  
  186. void DailyTickets(void)
  187. {
  188. printf("\n\n");
  189. printf("#of Children for daily tickets: " );
  190. fflush( stdout );
  191. DailyChild = price( DChild );
  192. printf("\n\n");
  193.  
  194.  
  195. printf("#of Adults for daily tickets: " );
  196. fflush( stdout );
  197. DailyAdult = price( DAdult );
  198. printf("\n\n");
  199.  
  200.  
  201. printf("#of Seniors for daily tickets: " );
  202. fflush( stdout );
  203. DailySenior = price( DSenior );
  204. printf("\n\n");
  205.  
  206.  
  207. return;
  208. }
  209.  
  210. /*+*+*+*+*+*+*+* Allows the user to enter yearly tickets *+*+*+*+*+*+*+*/
  211.  
  212. void YearlyTickets(void)
  213. {
  214. printf("\n\n");
  215. printf("#of Children for yearly tickets: " );
  216. fflush( stdout );
  217. YearlyChild = price( YChild );
  218. printf("\n\n");
  219.  
  220.  
  221. printf("#of Adults for yearly tickets: " );
  222. fflush( stdout );
  223. YearlyAdult = price( YAdult );
  224. printf("\n\n");
  225.  
  226.  
  227. printf("#of Seniors for yearly tickets: " );
  228. fflush( stdout );
  229. YearlySenior = price( YSenior );
  230. system("pause");
  231. printf("\n\n\n");
  232.  
  233. return;
  234. }
  235.  
  236. /*+*+*+*+*+*+*+* Displays information that the user entered *+*+*+*+*+*+*+*/
  237.  
  238. void NewPageDisplay(void)
  239. {
  240. system("cls");
  241.  
  242. PrintAStarLine();
  243. printf(" Home Aquarium Contract \n");
  244. printf("\n\n");
  245. PrintAStarLine();
  246.  
  247.  
  248. printf("CustomerName: %s \n", customerName);
  249.  
  250.  
  251. if(strcmp(TicketNumber,"D")==0)
  252. {
  253. printf("Type of ticket: Daily \n", TicketNumber);
  254. printf("\n\n");
  255. }
  256. else if(strcmp(TicketNumber,"d")==0)
  257. {
  258. printf("Type of ticket: Daily \n", TicketNumber);
  259. printf("\n\n");
  260. }
  261. else if(strcmp(TicketNumber,"Daily")==0)
  262. {
  263. printf("Type of ticket: Daily \n", TicketNumber);
  264. printf("\n\n");
  265. }
  266. else if(strcmp(TicketNumber,"daily")==0)
  267. {
  268. printf("Type of ticket: Daily \n", TicketNumber);
  269. printf("\n\n");
  270. }
  271. else if (TicketNumber == "Y")
  272. {
  273. printf("Type of ticket: Yearly \n", TicketNumber);
  274. printf("\n\n");
  275. }
  276. else if(strcmp(TicketNumber,"y")==0)
  277. {
  278. printf("Type of ticket: Yearly \n", TicketNumber);
  279. printf("\n\n");
  280. }
  281. else if(strcmp(TicketNumber,"Yearly")==0)
  282. {
  283. printf("Type of ticket: Yearly \n", TicketNumber);
  284. printf("\n\n");
  285. }
  286. else if(strcmp(TicketNumber,"yearly")==0)
  287. {
  288. printf("Type of ticket: Yearly \n", TicketNumber);
  289. printf("\n\n");
  290. }
  291.  
  292.  
  293. system("pause");
  294. printf(" Charge Number %s \n", NumberName);
  295. printf("\n\n");
  296. printf( "Child: $%6.2f\n", TotalChild );
  297. printf("\n");
  298. printf( "Adult: $%6.2f\n", TotalAdult );
  299. printf("\n");
  300. printf( "Senior: $%6.2f\n", TotalSenior );
  301. printf("\n");
  302. printf(" ======= ======= %s \n", Underlines);
  303. printf("\n\n");
  304. printf( "Total: $%6.2f\n", TotalCost );
  305. printf("\n");
  306. printf( "Less Discount: $%6.2f\n", LessDiscount );
  307. printf("\n");
  308. printf( "Total After Discount: $%6.2f\n", TotalDiscount );
  309. printf("\n");
  310.  
  311. return;
  312. }
  313.  
  314. /*+*+*+*+*+*+*+* Performs Calculations *+*+*+*+*+*+*+*/
  315.  
  316. void Calculations(void)
  317. {
  318.  
  319.  
  320.  
  321.  
  322. TotalChild = (DailyChild + YearlyChild);
  323. TotalAdult = (DailyAdult + YearlyAdult);
  324. TotalSenior = (DailySenior + YearlySenior);
  325. TotalCost = (TotalAdult) + (TotalSenior) + (TotalChild);
  326.  
  327. if (DailyAdult > 2)
  328. LessDiscount = TotalCost * .10;
  329.  
  330. else if (YearlyAdult > 2)
  331. LessDiscount = TotalCost * .10;
  332.  
  333. else if (DailySenior > 3)
  334. LessDiscount = TotalCost * .10;
  335.  
  336. else if (YearlySenior > 3)
  337. LessDiscount = TotalCost * .10;
  338. else
  339. LessDiscount = TotalCost - TotalCost;
  340. TotalDiscount = (TotalCost) - (LessDiscount);
  341.  
  342. return;
  343.  
  344. }
  345.  
  346. /*+*+*+*+*+*+*+* Asks The User A Question *+*+*+*+*+*+*+*/
  347.  
  348. void AskQuestion(void)
  349. {
  350. printf("\n\nAre we done for the day? (Y/N)");
  351. scanf(" %c", &aQuestion);
  352. fflush(stdin);
  353.  
  354.  
  355. return;
  356. }
  357.  
  358. /*+*+*+*+*+*+*+* Displays Final Cost to User *+*+*+*+*+*+*+*/
  359.  
  360. void SecondPageDisplay(void)
  361. {
  362.  
  363. system("cls");
  364.  
  365. PrintAStarLine();
  366. printf(" Home Aquarium Daily Totals \n");
  367. printf("\n\n");
  368. PrintAStarLine();
  369.  
  370. printf("Total Total \nNumber Income %s \n", TotalIncome);
  371.  
  372. printf("\n\n");
  373. printf(" Child: $%6.2f\n", TotalChild );
  374. printf("\n");
  375. printf( " Adult: $%6.2f\n", TotalAdult );
  376. printf("\n");
  377. printf( " Senior: $%6.2f\n", TotalSenior );
  378. printf("\n");
  379.  
  380. printf("________________________________________________________________________________%s \n", Underlines);
  381.  
  382.  
  383. printf( "Grand Total: $%6.2f\n", TotalCost );
  384. printf("\n");
  385.  
  386. printf( "Grand Total After Discount: $%6.2f\n", TotalDiscount );
  387. printf("\n");
  388.  
  389. return;
  390.  
  391. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Concerning C++ calculations using printf

 
0
  #17
Aug 7th, 2007
char tickettype[];
This array needs a subscript limit inside the brackets.

To improve your code and skills I suggest you do some reading
about:
Scope. The life and range of variable declarations.
Global variables.
And the key word switch.
At some point you will have to star using pointers in the
functions to avoid all those Global variables.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Concerning C++ calculations using printf

 
0
  #18
Aug 9th, 2007
Thanks for the help Aia. I got my project back and wanted to know how would I be able to display the amount of either nails or screws purchased in your program below. For it to be next to the cost of them. For example it should look something like this.
  1. /*
  2. Number Price
  3. Nails: 2 $0.50
  4. Screws: 2 $1.00
  5.  
  6. */
This is the code you did earlier

  1. /*
  2.  * HomeDepot.c
  3.  * Shows how to match item with price.
  4.  */
  5. #include <stdio.h>
  6.  
  7. float price( const float item )
  8. {
  9. int piece = 0;
  10. char newline;
  11.  
  12. scanf( "%d%c", &piece, &newline ); /* amount of items */
  13.  
  14. return item * piece;
  15. }
  16.  
  17. int main( void )
  18. {
  19. const float screw = .50; /* this never should change */
  20. const float nail = .25; /* this never should change */
  21. float price_screws = 0.00; /* final total price items */
  22. float price_nails = 0.00; /* final total price items */
  23.  
  24.  
  25. /* ask for nails */
  26. printf( " Enter amount of nails: " );
  27. fflush( stdout ); /* refresh the screen */
  28.  
  29. /* get & compute the total price of nails */
  30. price_nails = price( nail );
  31.  
  32. /* ask for screws */
  33. printf( "Enter amount of screws: " );
  34. fflush( stdout ); /* refresh the screen */
  35.  
  36. /* get & compute the total price of screws */
  37. price_screws = price( screw );
  38.  
  39. /* final display */
  40. puts( "\n\tYour total order" );
  41. puts( "\t================\n");
  42. printf( " Price for nails: %6.2f\n", price_nails );
  43. printf( "Price for screws: %6.2f\n", price_screws );
  44. printf( " Grand total: %6.2f\n", price_nails + price_screws );
  45.  
  46. getchar();
  47. return 0;
  48. }
  49. /*
  50.  my input / output.
  51.   Enter amount of nails: 34
  52. Enter amount of screws: 23
  53.  
  54.   Your total order
  55.   ================
  56.  
  57.  Price for nails: $ 8.50
  58. Price for screws: $ 11.50
  59.   Grand total: $ 20.00
  60.  
  61. */
Last edited by NycNessyness; Aug 9th, 2007 at 6:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Concerning C++ calculations using printf

 
0
  #19
Aug 9th, 2007
>how would I be able to display the amount of either nails or screws purchased


Here's where you need some knowledge about variable scope and pointers.
First: piece is a local variable declared in the price function which it will be destroyed as soon as the function exits.
We need to keep those values obtained by the function price alive. How?. We can declare in main some variables to hold the values, and them pass those variables as pointers to the function.

Example:
  1. /*
  2.  * HomeDepot.c
  3.  * Shows how to match item with price.
  4.  */
  5. #include <stdio.h>
  6.  
  7. /* function price has now two parameters
  8.  * a float for the price
  9.  * a pointer type int for the item
  10.  * returns a float for total price times item
  11.  */
  12. float price( const float item, int *piece )
  13. {
  14. char newline;
  15.  
  16. scanf( "%d%c", piece, &newline ); /* amount of items */
  17.  
  18. return item * (*piece); /* piece is a pointer to another variable, to access what's in that variable you have to use the * operand to dereference it */
  19. }
  20.  
  21. int main( void )
  22. {
  23. const float screw = .50; /* this never should change */
  24. const float nail = .25; /* this never should change */
  25. float price_screws = 0.00; /* final total price items */
  26. float price_nails = 0.00; /* final total price items */
  27. /* new variables */
  28. int A_nails = 0; /* amount of nails wanted */
  29. int A_screws = 0; /* amount of screws requested */
  30.  
  31.  
  32. /* ask for nails */
  33. printf( " Enter amount of nails: " );
  34. fflush( stdout ); /* refresh the screen */
  35.  
  36. /* get & compute the total price of nails */
  37. price_nails = price( nail, &A_nails ); /* the & is "address of" operand */
  38.  
  39. /* ask for screws */
  40. printf( "Enter amount of screws: " );
  41. fflush( stdout ); /* refresh the screen */
  42.  
  43. /* get & compute the total price of screws */
  44. price_screws = price( screw, &A_screws );/* Same here, the & is "address of" operand */
  45.  
  46. /* final display */
  47. puts( "\n\tYour total order" );
  48. puts( "\t================\n");
  49. puts( "\tNumber\tPrice");
  50. printf("Nails:\t%5d\t%.2f\n", A_nails, price_nails );
  51. printf("Screws:\t%5d\t%.2f\n", A_screws, price_screws );
  52. printf("Grand total: %.2f\n", price_nails + price_screws );
  53.  
  54. getchar();
  55. return 0;
  56. }
  57. /* My input/output:
  58. Enter amount of nails: 2
  59. Enter amount of screws: 3
  60.  
  61.   Your total order
  62.   ================
  63.  
  64.   Number Price
  65. Nails: 2 0.50
  66. Screws: 3 1.50
  67. Grand total: 2.00
  68. */
Last edited by Aia; Aug 9th, 2007 at 8:08 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Concerning C++ calculations using printf

 
0
  #20
Aug 9th, 2007
Thanks Aia. I tried using the example you gave me, but came up with error messages saying "cannot convert parameter 1 from 'int *' to 'const float'". I'm still trying to make my program display the number entered by the price. Not sure what to do about it, but heres how my code is looking.

  1.  
  2. /*+*+*+*+*+*+*+* Preprocessor Directives *+*+*+*+*+*+*+*/
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. /*+*+*+*+*+*+*+* Function Prototypes *+*+*+*+*+*+*+*/
  9.  
  10.  
  11. void PrintAStarLine(void);
  12. void GetInput(void);
  13. void Tickets(void);
  14. void DailyTickets(void);
  15. void YearlyTickets(void);
  16. void DailyPageDisplay(void);
  17. void YearlyPageDisplay(void);
  18. void TotalPageDisplay(void);
  19. void DailyCalculations(void);
  20. void YearlyCalculations(void);
  21. void TotalCalculation(void);
  22. void AskQuestion(void);
  23.  
  24. /*+*+*+*+*+*+*+* Variables *+*+*+*+*+*+*+*/
  25.  
  26.  
  27.  
  28.  
  29. const float DChild = 1.50;
  30. float DailyChild = 0.00;
  31. int DailyChildNum = 0;
  32.  
  33. const float YChild = 5.50;
  34. float YearlyChild = 0.00;
  35. int YearlyChildNum = 0;
  36.  
  37.  
  38. const float DAdult = 2.00;
  39. float DailyAdult = 0.00;
  40. int DailyAdultNum = 0;
  41.  
  42. const float YAdult = 6.50;
  43. float YearlyAdult = 0.00;
  44. int YearlyAdultNum = 0;
  45.  
  46. const float DSenior = 1.25;
  47. float DailySenior = 0.00;
  48. int DailySeniorNum = 0;
  49.  
  50. const float YSenior = 3.75;
  51. float YearlySenior = 0.00;
  52. int YearlySeniorNum = 0;
  53.  
  54. float DailyCost;
  55. float YearlyCost;
  56. float TotalCost;
  57.  
  58. float DailyDiscount;
  59. float YearlyDiscount;
  60. float TotalDiscount;
  61.  
  62. float TotalChild;
  63. float TotalAdult;
  64. float TotalSenior;
  65.  
  66. float DailyTotal;
  67. float YearlyTotal;
  68. float Total;
  69.  
  70. char customerName[30];
  71. char tickettype[8];
  72. char TicketNumber[8];
  73. char NumberName[10];
  74. char Underlines[10];
  75. char aQuestion;
  76. char TotalIncome[10];
  77.  
  78.  
  79. float price( const float ticket, int *num )
  80. {
  81. char newline;
  82.  
  83. scanf( "%d%c", num, &newline );
  84.  
  85. return ticket * (*num);
  86. }
  87.  
  88. /*+*+*+*+*+*+*+*^ The Main Module ^*+*+*+*+*+*+*+*/
  89.  
  90.  
  91. int main( void )
  92. {
  93.  
  94.  
  95.  
  96.  
  97.  
  98. PrintAStarLine();
  99.  
  100. printf(" Home Aquarium Data Entry \n");
  101. printf("\n\n");
  102.  
  103. PrintAStarLine();
  104.  
  105. aQuestion = 'N'; /* It will loop until user enter YES or YES */
  106. while ((aQuestion != 'Y') && (aQuestion != 'y')) /*sets value to go into loop the first time */
  107. {
  108. GetInput();
  109.  
  110. Tickets();
  111.  
  112. AskQuestion();
  113. }
  114.  
  115. system("cls");
  116.  
  117. TotalCalculation();
  118.  
  119. TotalPageDisplay();
  120.  
  121. return 0;
  122. }
  123.  
  124. /*+*+*+*+*+*+*+* Avoids making the program look real plain *+*+*+*+*+*+*+*/
  125.  
  126. void PrintAStarLine(void)
  127.  
  128. {
  129.  
  130. printf("******************************************************************************** \n");
  131. printf("\n\n");
  132.  
  133. return;
  134.  
  135. }
  136.  
  137.  
  138. /*+*+*+*+*+*+*+* Asks The User for their name *+*+*+*+*+*+*+*/
  139.  
  140. void GetInput(void)
  141. {
  142.  
  143.  
  144.  
  145. printf("Customer Name: ");
  146. scanf( "%[^\n]", customerName);
  147. printf("\n\n\n");
  148.  
  149. return;
  150. }
  151.  
  152.  
  153. /*+*+*+*+*+*+*+* Asks The User what ticket type they want *+*+*+*+*+*+*+*/
  154.  
  155. void Tickets(void)
  156. {
  157.  
  158. printf("\n\nType of ticket: ");
  159. scanf(" %s", &TicketNumber);
  160.  
  161.  
  162. if(strcmp(TicketNumber,"D")==0)
  163. {
  164. DailyTickets();
  165. DailyCalculations();
  166. DailyPageDisplay();
  167. }
  168. else if(strcmp(TicketNumber,"d")==0)
  169. {
  170. DailyTickets();
  171. DailyCalculations();
  172. DailyPageDisplay();
  173. }
  174. else if(strcmp(TicketNumber,"daily")==0)
  175. {
  176. DailyTickets();
  177. DailyCalculations();
  178. DailyPageDisplay();
  179. }
  180. else if(strcmp(TicketNumber,"Daily")==0)
  181. {
  182. DailyTickets();
  183. DailyCalculations();
  184. DailyPageDisplay();
  185. }
  186. else if(strcmp(TicketNumber,"Y")==0)
  187. {
  188. YearlyTickets();
  189. YearlyCalculations();
  190. YearlyPageDisplay();
  191. }
  192. else if(strcmp(TicketNumber,"y")==0)
  193. {
  194. YearlyTickets();
  195. YearlyCalculations();
  196. YearlyPageDisplay();
  197. }
  198. else if(strcmp(TicketNumber,"Yearly")==0)
  199. {
  200. YearlyTickets();
  201. YearlyCalculations();
  202. YearlyPageDisplay();
  203. }
  204. else if(strcmp(TicketNumber,"yearly")==0)
  205. {
  206. YearlyTickets();
  207. YearlyCalculations();
  208. YearlyPageDisplay();
  209. }
  210. else
  211. {
  212. printf("\n Incorrect Ticket Number Entered, please try again! \n");
  213. printf("\n");
  214. Tickets();
  215. }
  216. printf("\n");
  217. return;
  218. }
  219.  
  220. /*+*+*+*+*+*+*+* Allows the user to enter daily tickets *+*+*+*+*+*+*+*/
  221.  
  222. void DailyTickets(void)
  223. {
  224.  
  225. printf("\n\n");
  226. printf("#of Children: " );
  227. DailyChild = price( &DailyChildNum, DChild );
  228. printf("\n\n");
  229.  
  230.  
  231. printf("#of Adults: " );
  232. DailyAdult = price( &DailyAdultNum, DAdult );
  233. printf("\n\n");
  234.  
  235.  
  236. printf("#of Seniors: " );
  237. DailySenior = price( &DailySeniorNum, DSenior );
  238. printf("\n\n");
  239.  
  240.  
  241. return;
  242. }
  243.  
  244. /*+*+*+*+*+*+*+* Allows the user to enter yearly tickets *+*+*+*+*+*+*+*/
  245.  
  246. void YearlyTickets(void)
  247. {
  248. printf("\n\n");
  249. printf("#of Children: " );
  250. YearlyChild = price( &YearlyChildNum, YChild );
  251. printf("\n\n");
  252.  
  253.  
  254. printf("#of Adults: " );
  255. YearlyAdult = price( &YearlyAdultNum, YAdult );
  256. printf("\n\n");
  257.  
  258.  
  259. printf("#of Seniors: " );
  260. YearlySenior = price( &YearlySeniorNum, YSenior );
  261. system("pause");
  262. printf("\n\n\n");
  263.  
  264. return;
  265. }
  266.  
  267. /*+*+*+*+*+*+*+* Displays information that the user entered *+*+*+*+*+*+*+*/
  268.  
  269. void DailyPageDisplay(void)
  270. {
  271. system("cls");
  272.  
  273. PrintAStarLine();
  274. printf(" Home Aquarium Contract \n");
  275. printf("\n\n");
  276. PrintAStarLine();
  277.  
  278.  
  279. printf("Customer: %s \n", customerName);
  280.  
  281.  
  282. if(strcmp(TicketNumber,"D")==0)
  283. {
  284. printf("Type of ticket: Daily \n", TicketNumber);
  285. printf("\n\n");
  286. }
  287. else if(strcmp(TicketNumber,"d")==0)
  288. {
  289. printf("Type of ticket: Daily \n", TicketNumber);
  290. printf("\n\n");
  291. }
  292. else if(strcmp(TicketNumber,"Daily")==0)
  293. {
  294. printf("Type of ticket: Daily \n", TicketNumber);
  295. printf("\n\n");
  296. }
  297. else if(strcmp(TicketNumber,"daily")==0)
  298. {
  299. printf("Type of ticket: Daily \n", TicketNumber);
  300. printf("\n\n");
  301. }
  302.  
  303.  
  304.  
  305. system("pause");
  306. printf(" Number Charge %s \n", NumberName);
  307. printf("\n\n");
  308. printf( "Child: %5d $%6.2f\n", DailyChildNum, DailyChild );
  309. printf("\n");
  310. printf( "Adult: %5d $%6.2f\n", DailyAdultNum, DailyAdult );
  311. printf("\n");
  312. printf( "Senior: %5d $%6.2f\n", DailySeniorNum, DailySenior );
  313. printf("\n");
  314. printf(" ======= ======= %s \n", Underlines);
  315. printf("\n\n");
  316. printf( "Total: $%6.2f\n", DailyCost );
  317. printf("\n");
  318. printf( "Less Discount: $%6.2f\n", DailyDiscount );
  319. printf("\n");
  320. printf( "Total After Discount: $%6.2f\n", DailyTotal );
  321. printf("\n");
  322.  
  323. return;
  324. }
  325.  
  326. /*+*+*+*+*+*+*+* Displays information that the user entered *+*+*+*+*+*+*+*/
  327.  
  328. void YearlyPageDisplay(void)
  329. {
  330. system("cls");
  331.  
  332. PrintAStarLine();
  333. printf(" Home Aquarium Contract \n");
  334. printf("\n\n");
  335. PrintAStarLine();
  336.  
  337.  
  338. printf("Customer: %s \n", customerName);
  339.  
  340.  
  341. if (TicketNumber == "Y")
  342. {
  343. printf("Type of ticket: Yearly \n", TicketNumber);
  344. printf("\n\n");
  345. }
  346. else if(strcmp(TicketNumber,"y")==0)
  347. {
  348. printf("Type of ticket: Yearly \n", TicketNumber);
  349. printf("\n\n");
  350. }
  351. else if(strcmp(TicketNumber,"Yearly")==0)
  352. {
  353. printf("Type of ticket: Yearly \n", TicketNumber);
  354. printf("\n\n");
  355. }
  356. else if(strcmp(TicketNumber,"yearly")==0)
  357. {
  358. printf("Type of ticket: Yearly \n", TicketNumber);
  359. printf("\n\n");
  360. }
  361.  
  362.  
  363. system("pause");
  364. printf(" Number Charge %s \n", NumberName);
  365. printf("\n\n");
  366. printf( "Child: %5d $%6.2f\n", YearlyChildNum, YearlyChild );
  367. printf("\n");
  368. printf( "Adult: %5d $%6.2f\n", YearlyAdultNum, YearlyAdult );
  369. printf("\n");
  370. printf( "Senior: %5d $%6.2f\n", YearlySeniorNum, YearlySenior );
  371. printf("\n");
  372. printf(" ======= ======= %s \n", Underlines);
  373. printf("\n\n");
  374. printf( "Total: $%6.2f\n", YearlyCost );
  375. printf("\n");
  376. printf( "Less Discount: $%6.2f\n", YearlyDiscount );
  377. printf("\n");
  378. printf( "Total After Discount: $%6.2f\n", YearlyTotal );
  379. printf("\n");
  380.  
  381. return;
  382. }
  383.  
  384. /*+*+*+*+*+*+*+* Performs Calculations *+*+*+*+*+*+*+*/
  385.  
  386. void DailyCalculations(void)
  387. {
  388.  
  389.  
  390. /* Performs Daily Calculations */
  391.  
  392.  
  393. DailyCost = (DailyChild) + (DailyAdult) + (DailySenior);
  394.  
  395. if ((DailyAdult > 2) && (DailyChild > 1))
  396. DailyDiscount = float(DailyCost * .10);
  397.  
  398. else if ((DailySenior > 3) && (DailyChild > 1))
  399. DailyDiscount = float(DailyCost * .10);
  400.  
  401. else
  402. DailyDiscount = (DailyCost - DailyCost);
  403. DailyTotal = (DailyCost - DailyDiscount);
  404.  
  405. return;
  406. }
  407.  
  408.  
  409.  
  410.  
  411. void YearlyCalculations(void)
  412. {
  413. /* Performs Yearly Calculations */
  414.  
  415.  
  416. YearlyCost = (YearlyChild) + (YearlyAdult) + (YearlySenior);
  417.  
  418. if ((YearlyAdult > 2) && (YearlyChild > 1))
  419. YearlyDiscount = float(YearlyCost * .10);
  420.  
  421. else if ((YearlySenior > 3) && (YearlyChild > 1))
  422. YearlyDiscount = float(YearlyCost * .10);
  423. else
  424. YearlyDiscount = (YearlyCost - YearlyCost);
  425. YearlyTotal = (YearlyCost - YearlyDiscount);
  426.  
  427. return;
  428.  
  429. }
  430.  
  431. void TotalCalculation(void)
  432. {
  433. /* Performs Yearly Calculations */
  434.  
  435. TotalChild = (DailyChild + YearlyChild) ;
  436. TotalAdult = (DailyAdult + YearlyAdult);
  437. TotalSenior = (DailySenior + YearlySenior);
  438. TotalCost = (DailyCost + YearlyCost);
  439. TotalDiscount = (DailyDiscount + YearlyDiscount);
  440. Total = (TotalCost - TotalDiscount);
  441.  
  442. }
  443.  
  444. /*+*+*+*+*+*+*+* Asks The User A Question *+*+*+*+*+*+*+*/
  445.  
  446. void AskQuestion(void)
  447. {
  448. printf("\n\nAre we done for the day? (Yes/No)");
  449. scanf(" %c", &aQuestion);
  450. fflush(stdin);
  451.  
  452.  
  453.  
  454. return;
  455. }
  456.  
  457. /*+*+*+*+*+*+*+* Displays Final Cost to User *+*+*+*+*+*+*+*/
  458.  
  459. void TotalPageDisplay(void)
  460. {
  461.  
  462. system("cls");
  463.  
  464. PrintAStarLine();
  465. printf(" Home Aquarium Daily Totals \n");
  466. printf("\n\n");
  467. PrintAStarLine();
  468.  
  469. printf("Total Total \nNumber Income %s \n", TotalIncome);
  470.  
  471. printf("\n\n");
  472. printf(" Child: $%6.2f\n", TotalChild );
  473. printf("\n");
  474. printf( " Adult: $%6.2f\n", TotalAdult );
  475. printf("\n");
  476. printf( " Senior: $%6.2f\n", TotalSenior );
  477. printf("\n");
  478.  
  479. printf("________________________________________________________________________________%s \n", Underlines);
  480.  
  481.  
  482. printf( "Grand Total: $%6.2f\n", TotalCost );
  483. printf("\n");
  484.  
  485. printf( "Grand Total After Discount: $%6.2f\n", Total );
  486. printf("\n");
  487.  
  488. return;
  489.  
  490. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC