Can comeone just check my code plz

Thread Solved

Join Date: Apr 2008
Posts: 23
Reputation: Taker has a little shameless behaviour in the past 
Solved Threads: 0
Taker Taker is offline Offline
Newbie Poster

Can comeone just check my code plz

 
0
  #1
Apr 10th, 2008
  1. #include <stdio.h>
  2.  
  3.  
  4. struct places
  5. {
  6. char places1[100];
  7. char places[10][10];
  8. int distances[10][10];
  9. };
  10.  
  11.  
  12. main()
  13. {
  14. int menu;
  15. char userinput1[10];
  16. char userinput2[10];
  17. char userinput3[10];
  18. int cost;
  19. int other;
  20. int a;
  21. int b;
  22. int c;
  23. int distances;
  24. char places[50];
  25. struct places names[10];
  26.  
  27. FILE *fp; /*creates a file pointed named fp*/
  28.  
  29. /* reading in data from file*/
  30. do
  31. {
  32. printf("Enter file name");
  33. scanf("%s", places);
  34. fp = fopen(places,"r");
  35. if (fp == NULL)
  36. printf("File %s does not exist\n",places);
  37. }
  38. while(fp ==NULL);
  39.  
  40. while(feof(fp) ==0)
  41. {
  42. for(int i = 0; i < 10; i++)
  43. {
  44. fscanf(fp, "%s", &names[i].places);
  45. }
  46. for(int i = 0; i < 10; i ++)
  47. {
  48. for(int j = 0; j < 10; j++)
  49. {
  50. fscanf(fp, "%d", &names.distances[i][j]);
  51. }
  52. }
  53.  
  54. for(int i = 0; i < 10; i ++)
  55. {
  56. for(int j = 0; j < 10; j++)
  57. {
  58. for(int h = 0; h < 10; h++)
  59. {
  60. fscanf(fp, "%d", &names.distances[i][j][h]);
  61. }
  62. }
  63. }
  64.  
  65. }
  66.  
  67.  
  68. /* menu */
  69.  
  70. do
  71. {
  72. printf("what would you like to do\n");
  73. printf(" 1: display mileage table");
  74. printf(" 2: calulate distances between points");
  75. printf(" 3: calulate cost of journey");
  76. printf(" 4: exit");
  77. scanf("%d", &menu);
  78.  
  79. switch(menu)
  80. {
  81. case 1:
  82. display(distances, names);
  83. break;
  84. case 2:
  85. distance(distances, names);
  86. break;
  87. case 3:
  88. calc(distances,names);
  89. break;
  90. case 4:
  91. exit(0);
  92. break;
  93. }
  94.  
  95. }
  96. while(menu<5 && menu > 0);
  97.  
  98. }
  99.  
  100. /* display mileage chart*/
  101.  
  102. int display(int distances[][10], struct places names[10])
  103. {
  104. printf(" mileage chart");
  105. printf("Burton Derby Swad Stoke Staff Lincoln Walsall Telford Cannock Warwick");
  106.  
  107. for(int i = 0; i<10; i++)
  108. {
  109. for(int j = 0; j < 10; j++)
  110. {
  111. printf("%7s",names[i].places);
  112. printf("%7d", distances[i][j]);
  113.  
  114. }
  115. }
  116. }
  117.  
  118. /*distance between points*/
  119. int distance( int distances[][10], struct places names[10])
  120. {
  121.  
  122. printf("Burton");
  123. printf("Derby");
  124. printf("Swad");
  125. printf("Stoke");
  126. printf("Stafford");
  127. printf("Lincoln");
  128. printf("Walsall");
  129. printf("Telford");
  130. printf("Cannock");
  131. printf("Warwick");
  132.  
  133. printf("Enter the first point from the above list");
  134. scanf("%s", &userinput1);
  135.  
  136. for (int i = 0; i<10; i++)
  137. {
  138. if(strcmp(userinput1, names[i].places) ==0)
  139. {
  140. a = i;
  141. }
  142. else
  143. {
  144. printf("Please enter a place from the list");
  145. }
  146.  
  147. printf("Enter the second point from the above list");
  148. scanf("%s", &userinput2);
  149.  
  150. for(int j = 0; j <10;j++)
  151. {
  152. if(strcmp(userinput2, names[j].places) == 0)
  153. {
  154. b = j;
  155. }
  156. else
  157. {
  158. printf("Please enter a place from the list");
  159. }
  160.  
  161. printf("The distance is %d", distances[a][b]);
  162.  
  163. }
  164.  
  165. printf("Enter the third point from the above list");
  166. scanf("%s", &userinput3);
  167.  
  168. for(int h = 0; h <10;j++)
  169. {
  170. if(strcmp(userinput3, names[h].places) == 0)
  171. {
  172. c = h;
  173. }
  174. else
  175. {
  176. printf("Please enter a place from the list");
  177. }
  178.  
  179. printf("The distance is %d", distances[a][b][c]);
  180.  
  181. }
  182. }
  183.  
  184.  
  185.  
  186. /*calculations between points*/
  187. int calc(int distances[][10], struct places names[10]);
  188. {
  189. printf("Burton");
  190. printf("Lincoln");
  191. printf("Walsall");
  192. printf("Telford");
  193. printf("Cannock");
  194. printf("Warwick");
  195. printf("Derby");
  196. printf("Swad");
  197. printf("Stoke");
  198. printf("Stafford");
  199.  
  200. printf("Enter the first point from the list");
  201. scanf("%s", userinput1);
  202.  
  203. for (int i = 0; i <10; i++)
  204. {
  205. if(strcmp(userinput1, names[i].places) == 0)
  206. {
  207. a = i;
  208. }
  209. else
  210. {
  211. Printf("Please enter a point from the list");
  212. }
  213. }
  214.  
  215.  
  216. printf("Enter the second point from the list");
  217. scanf("%s", userinput2);
  218.  
  219. for(int j = 0; j < 10; j++)
  220. {
  221. if(strcmp(userinput2, names[j].places) ==0)
  222. {
  223. b = j;
  224. }
  225. else
  226. {
  227. Printf("Enter a point from the list");
  228. }
  229. }
  230.  
  231. printf("Enter the thrid point from the above list");
  232. scanf("%s", &userinput3);
  233.  
  234. for(int h = 0; h <10;j++)
  235. {
  236. if(strcmp(userinput3, names[h].places) == 0)
  237. {
  238. c = h;
  239. }
  240. else
  241. {
  242. printf("Please enter a place from the list");
  243. }
  244.  
  245. printf("The distance is %d", distances[a][b][c]);
  246.  
  247. }
  248.  
  249. if(distances[a][b][c] <= 100)
  250. {
  251. cost = ((distances[a][b][c] * 40)/100);
  252. printf("The cost is %d", &cost);
  253. }
  254. else
  255. {
  256. other = distances[a][b][c] - 100;
  257. other = other * 30;
  258. cost = (100 * 40) + other;
  259. cost = cost/100;
  260.  
  261. printf("The cost of the journy is %d", &cost);
  262.  
  263. }
  264. }
  265. }

Error message Line 7 In declartion "places", or no linkage an delared in same struct

how do i get this error message to go away
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: Can comeone just check my code plz

 
0
  #2
Apr 10th, 2008
struct places
{
char places1[100];
char places[10][10];

Pick a different name.

Your use of feof() is wrong as well.
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 23
Reputation: Taker has a little shameless behaviour in the past 
Solved Threads: 0
Taker Taker is offline Offline
Newbie Poster

Re: Can comeone just check my code plz

 
0
  #3
Apr 10th, 2008
Thanks I put what was wrong right cheeers
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