943,565 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1647
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 24th, 2008
1

Need help with struct records!

Expand Post »
Ok so here is the code I've written already, as well as the errors I get when I try to build. Please help me figure out what the problem is!

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6.  
  7. #define COMPANY "Rocklin Realty"
  8. #define TRUE 1
  9. #define TAB 25
  10.  
  11. void setagents(double *a, int c);
  12. void total_sales(double *m, char **cal, int c);
  13. void agent_sales(double *m, char **cal, int c);
  14. void valid_date(char *date, int min_yr, int max_yr);
  15. void titles(void);
  16. int headings(void);
  17. int menu(void);
  18. void add(void);
  19. int quit(void);
  20. void message(char *msg);
  21. int menuvalid(int min, int max, char item[]);
  22.  
  23.  
  24. char *names[] = {"Larry Lister", "Sue Sales", "Eva Escrow", "Morley Money", "Pete Profit" };
  25.  
  26.  
  27.  
  28. typedef struct
  29. {
  30. char aname[15], date[9];
  31. int acode;
  32. double price;
  33. } REALTOR;
  34.  
  35.  
  36. #define clrscr() system("cls")
  37.  
  38. int main()
  39. {
  40.  
  41. int key, more = TRUE;
  42. do
  43. {
  44. key = menu();
  45. switch (key)
  46. {
  47. case 1: add(); break;
  48. case 2: total_sales(); break;
  49. case 3: agent_sales(); break;
  50. case 4: more = quit(); break;
  51. default: message("\nError in selection\a");
  52. }
  53. }
  54. while (more);
  55. return 0;
  56. }
  57. /* ================================================================ */
  58. int menu()
  59. {
  60. int choice;
  61. titles();
  62. printf("1 = Add Records\n", TAB, ' ');
  63. printf("2 = Report Total Sales\n", TAB, ' ');
  64. printf("3 = Report Agent Sales\n", TAB, ' ');
  65. printf("\4 = Quit\n", TAB, ' ');
  66.  
  67. choice = menuvalid(1, 4, "choice");
  68. return(choice);
  69. }
  70. /* ================================================================ */
  71. /**/
  72. void add()
  73. {
  74. double agents[6];
  75. double price;
  76. int aname, c, more, items, key;
  77. char choice;
  78. REALTOR s;
  79. FILE *fp;
  80.  
  81.  
  82. fp = fopen("sales.dat", "w+b");
  83. if (fp == NULL)
  84. {
  85. message("Error opening sales.dat\a");
  86. return;
  87. }
  88. fseek(fp, 0L, SEEK_END);
  89. c = (int)ftell(fp) / sizeof(s);
  90. setagents(agents,6);
  91. do
  92. {
  93. printf("Enter an agent code (1-5): ");
  94. scanf("%d%*c", s.aname);
  95. printf("Enter sale date for %s: ", names[aname-1]);
  96. gets(s.date);
  97. printf("Enter the sale price : ");
  98. scanf("%lf%*c", s.price);
  99.  
  100. }
  101. /* ================================================================ */
  102. void titles()
  103. {
  104. clrscr();
  105. printf("%*c %s\n\n", TAB, ' ',COMPANY);
  106.  
  107. /* ================================================================ */
  108. void message(char *msg)
  109. {
  110. printf("%s, press Enter key to continue\n", msg);
  111. getchar();
  112. }
  113.  
  114. /* ================================================================ */
  115. int quit()
  116. {
  117. int c, more = TRUE;
  118. c = prompt("\nTerminate program");
  119. if (c == 'Y')
  120. {
  121. clrscr();
  122. message("\nRocklin Realty Sales Database terminated successfully");
  123. more = FALSE;
  124. }
  125. return more;
  126. }
  127.  
  128. /* ================================================================ */
  129.  
  130. void valid_date(char *date, int min_yr, int max_yr)
  131. {
  132. int mm, dd, yy, max_dd, good;
  133. char msg[80];
  134. do
  135. {
  136. printf("Enter the date (mm/dd/yy), press RETURN to quit: ");
  137. gets(date);
  138. if (!date[0]) return;
  139. good = parsedate(date, &mm, &dd, &yy);
  140. if (!good)
  141. {
  142. message("Date must be in mm/dd/yy format\a");
  143. continue;
  144. }
  145. if (yy < min_yr || yy > max_yr)
  146. {
  147. sprintf(msg, "Year out of range %d to %d\a", min_yr, max_yr);
  148. message(msg);
  149. good = FALSE;
  150. continue;
  151. }
  152. if (mm < 1 || mm > 12)
  153. {
  154. message("Month out of range\a");
  155. good = FALSE;
  156. continue;
  157. }
  158. if (mm==4 || mm==6 || mm==9 || mm==11) max_dd = 30;
  159. else if (mm==2)
  160. {
  161. if (ISLEAP(1900+yy)) max_dd = 29;
  162. else max_dd = 28;
  163. }
  164. else max_dd = 31;
  165. if (dd < 1 || dd > max_dd)
  166. {
  167. message("Day out of range\a");
  168. good = FALSE;
  169. continue;
  170. }
  171. }
  172. while (!good);
  173. }
  174. /* ================================================================ */
  175.  
  176. int menuvalid(int min, int max, char item[])
  177. {
  178. int n;
  179. char buffer[80];
  180. printf("Enter the %s %d to %d: ", item, min, max);
  181. gets(buffer);
  182. n = atoi(buffer);
  183. while (n < min || n > max)
  184. {
  185. message("\nRange Error\a");
  186. printf("Enter the %s %d to %d: ", item, min, max);
  187. gets(buffer);
  188. n = atoi(buffer);
  189. }
  190. return(n);
  191. }
  192. /* ================================================================ */

Errors:

Error 1: error C2660: 'total_sales' : function does not take 0 arguments

Error 2: error C2660: 'agent_sales' : function does not take 0 arguments

Error 3: error C2062: type 'void' unexpected

Error 4: error C2143: syntax error : missing ';' before '{'

Error 5: error C2601: 'message' : local function definitions are illegal

Error 6: error C2601: 'quit' : local function definitions are illegal

Error 7: error C2601: 'valid_date' : local function definitions are illegal

Error 8: error C2601: 'menuvalid' : local function definitions are illegal

Error 9: fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\janelle\my documents\homework april 22-29\c programming\final exam\final exam\final.cpp(80)' was matched c:\documents and settings\janelle\my documents\homework april 22-29\c programming\final exam\final exam\final.cpp
Similar Threads
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
nelledawg is offline Offline
59 posts
since Feb 2008
Jun 24th, 2008
0

Re: Need help with struct records!

nelledawg you could clearly see from the error message what the problem with the code is. Lets have a look at your some of your error message and the solutions for that error.

  1. Error 1: error C2660: 'total_sales' : function does not take 0 arguments

What does it say, its saying that total_sales function does that takes 0 number of arguments , which is right , because youm have prototypes the total_sales function as taking 3 arguments

  1. void total_sales(double *m, char **cal, int c);

And you are missing some braces her and there. And you need to sit down check the function prototypes, may be will reduce a hell lot of errors.

ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Jun 24th, 2008
0

Re: Need help with struct records!

Ok but when I put the arguments in I get even more errors.

Ex:
  1. case 2: total_sales(double *m, char **cal, int c); break;

I just don't know how I'm supposed to put the arguments in the case correctly.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
nelledawg is offline Offline
59 posts
since Feb 2008
Jun 24th, 2008
1

Re: Need help with struct records!

ohh nelledawg, where did you get the code from. It donst look like that you wrote the code. You need to look into some basic before you program anything like this. You are usinfg some advance pointer types which you need to under stand. Let me should a simple example on how to send arguments. Look at the following code. And arguments is something which you send it a function. These values will then we used in the function for it own processing. So might have been decided for that function does and you should be knowing needed to be sending. So for example

  1. int sun( int a, int b);

The above ius function which takes two integer arguments a & b. Now i know that function takes two integer argument and it works on that two argument. So when I call that function i call it through this way

  1. sum(1, 2);
  2.  
  3. or
  4.  
  5. int a = 10;
  6. int b = 20;
  7.  
  8. sum(a, b);

Now sit down and look at your code and see what arguments should be sent to the total_sales function.

ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Jun 25th, 2008
0

Re: Need help with struct records!

nelledogg,

i just gave you postive comment because i thought you wrote that nice code yourself. you said "here is the code i have written"

but then you obviously dont even know how to pass arguments into a simple function, as evidenced by your attempt case 2: total_sales(double *m, char **cal, int c);
so you DIDNT write any of this code, did you?

because the rest of your code is using far more advanced concepts than passing simple arguments to a function.

now why don't you tell the truth about what's going on here?
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jun 25th, 2008
0

Re: Need help with struct records!

hey by checking above posts, it reminds me of a concept in C, default arguments!.

I am not sure is there any concept of default aruments?

Thanks
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Jun 25th, 2008
0

Re: Need help with struct records!

Click to Expand / Collapse  Quote originally posted by Luckychap ...
hey by checking above posts, it reminds me of a concept in C, default arguments!.

I am not sure is there any concept of default arguments?

Thanks
Luckychap, C donst support default arguments. Its only on C++. Well as far as i know. I am pretty sure about it through.

ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Jun 25th, 2008
0

Re: Need help with struct records!

thanks buddy!
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Jun 25th, 2008
1

Re: Need help with struct records!

hi,
the first thing i noticed is there's no total_sales function, if u can c the total_sales just lemme know, so i wonder how case 2 gonna work, n just @ a 1st sight, there r more prototypes than the cases, maybe if u send us ur source we might help u figuring out whats wrong whith that, plus it will make us a gd exercice,
right guys?
Reputation Points: 25
Solved Threads: 0
Newbie Poster
barbiegirl is offline Offline
10 posts
since Mar 2008
Jun 25th, 2008
0

Re: Need help with struct records!

Click to Expand / Collapse  Quote originally posted by barbiegirl ...
hi,
the first thing i noticed is there's no total_sales function, if u can c the total_sales just lemme know, so i wonder how case 2 gonna work, n just @ a 1st sight, there r more prototypes than the cases, maybe if u send us ur source we might help u figuring out whats wrong whith that, plus it will make us a gd exercice,
right guys?
not really.

how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay?



.
Last edited by jephthah; Jun 25th, 2008 at 4:21 pm.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: How to create an MP3 player.
Next Thread in C Forum Timeline: Reversing doubly linked list?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC