Help with Error message

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 15
Reputation: Foxtildawn is an unknown quantity at this point 
Solved Threads: 0
Foxtildawn Foxtildawn is offline Offline
Newbie Poster

Help with Error message

 
0
  #1
Jan 31st, 2005
i get a couple error messages when i try to compile this program...I dont understand how to fix them and i was hoping for some help.....The error messages i get are:

error C2146: syntax error : missing ';' before identifier 'inData'
error C2501: 'ifstream' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found



here is my code:
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. void Get_Choice(char);
  7. void Process_Choice(float a[][100],char,int&,int&);
  8. void Load(float a[][100],int&,int&);
  9. void Display(float a[][100],int&,int&);
  10. float Average(float a[][100],int&,int&);
  11. float LargestNum(float a[][100],int&,int&);
  12. float SmallestNum(float a[][100],int&,int&);
  13. int Search(float a[][100],int&,int&);
  14. int Between(float a[][100],int&,int&);
  15. char choice;
  16. bool die =1;
  17.  
  18. ifstream inData;
  19. ofstream outData;
  20.  
  21. void main()
  22. {
  23. using namespace std;
  24. //ifstream inData;
  25. //ofstream outData;
  26.  
  27. int rowSize=0,colSize=0;
  28. float array[100][100];
  29. outData.open("data.dat"); //opens an output file
  30.  
  31. while(die)
  32. {
  33. cin.clear();
  34. Get_Choice(choice); //calls the menu function
  35. Process_Choice(array[][100],choice,colSize,rowSize);
  36. }
  37. }
  38. //prints out the menu
  39. void Get_Choice(char choice)
  40. {
  41. outData<<endl;
  42. cout<< "The following is the menu" << endl;
  43. outData<<"The following is the menu" << endl;
  44. cout<<endl;
  45. outData<<endl;
  46. cout<< "a. Load the array" << endl;
  47. outData<< "a. Load the array" << endl;
  48. cout<< "b. Sort the Array in ascending order" << endl;
  49. outData<< "b. Sort the Array in ascending order" << endl;
  50. cout<< "c. Average the Numbers" << endl;
  51. outData<< "c. Average the Numbers" << endl;
  52. cout<< "d. Find the smallest number" << endl;
  53. outData<< "d. Find the smallest number" << endl;
  54. cout<< "e. Find the largest number" << endl;
  55. outData<< "e. Find the largest number" << endl;
  56. cout<< "f. Search for a Number" <<endl;
  57. outData<< "f. Search for a Number" <<endl;
  58. cout<< "g. Check how many numbers are between two numbers" <<endl;
  59. outData<< "g. Check how many numbers are between two numbers" <<endl;
  60. cout<< " ENTER z TO QUIT " << endl;
  61. outData<< " ENTER z TO QUIT " << endl;
  62.  
  63. cout<< "Enter your choice"<< endl;
  64. outData<< "Enter your choice"<< endl;
  65. cin >> choice;
  66. }
  67.  
  68. //executes function based on users input
  69. void Process_Choice(float array[][100],char choice,int& rowSize,int& colSize)
  70. {
  71. switch(choice)
  72. {
  73. case 'a':
  74. Load(array[0][100],rowSize,colSize);
  75. Display(array[0][colSize],rowSize,colSize);
  76. break;
  77. case 'b':cout<<"Average: ";
  78. outData<<"Average: ";
  79. Average(array[0][colSize],rowSize,colSize);
  80. break;
  81. case 'c': cout<<"Largest Number in Array: ";
  82. outData<<"Largest Number in Array: ";
  83. LargestNum(array[0][colSize],rowSize,colSize);
  84. break;
  85. case 'd': cout<<"Smallest Number in Array: ";
  86. outData<<"Smallest Number in Array: ";
  87. SmallestNum(array[0][colSize],rowSize,colSize);
  88. break;
  89. case 'e': cout<< "The number is at position(s): ";
  90. outData<< "The number is at position(s): ";
  91. Search(array[0][colSize],rowSize,colSize);
  92. break;
  93. case 'f': cout<<"Numbers between: "<<
  94. outData<<"Numbers between: ";
  95. Between(array[0][colSize],rowSize,colSize);
  96. break;
  97. case 'z': cout<<"EXIT"<<endl;
  98. die = 0;
  99. break;
  100. default:
  101. cout<<"INVAILD ENTRY"<<endl;
  102. outData<<"INVAILD ENTRY"<<endl;
  103. break;
  104. }
  105. }
  106.  
  107. //loads array
  108. void Load(float array[][100],int& colSize,int& rowSize){
  109. {
  110. cout<< "Enter the row size then the column size: "<<endl;
  111. outData<< "Enter the row size then the column size: "<<endl;
  112. cin>>rowSize;
  113. cin>>colSize>>endl;
  114.  
  115. char answ;
  116.  
  117. //prompts the user for keyboard of file input
  118. cout<< "Would you like to input from File or Keyboard" << endl;
  119. outData<< "Would you like to input from File or Keyboard" << endl;
  120. cout<< "Enter 'f' or 'k'" << endl;
  121. outData<< "Enter 'f' or 'k'" << endl;
  122. cin>> answ;
  123.  
  124. //Keyborad input
  125. if(answ == 'k')
  126. {
  127. cout<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
  128. outData<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
  129. int i=0;
  130. int j=0;
  131.  
  132. while(cin)
  133. {
  134.  
  135. for(i=0;i<rowSize;i++)
  136. {
  137. for(j=0;j<colSize;j++)
  138. {
  139. cin >> array[i][j];
  140. outData<< array[i][j]<< " ";
  141. }
  142. }
  143. }
  144. }
  145. else
  146. {
  147. string fileName;
  148.  
  149. cout<< "Input file name, then press Ctrl-D, Enter" << endl;
  150. outData<< "Input file name, then press Ctrl-D, Enter" << endl;
  151. cin >> fileName;
  152. inData.open(fileName.c_str());
  153.  
  154. int i=0,j=0;
  155. while(inData)
  156. {
  157. for(i=0;i<rowSize;i++)
  158. {
  159. for(j=0;j<colSize;j++)
  160. {
  161. cin >> array[i][j];
  162. outData<< array[i][j]<< " ";
  163. }
  164. }
  165. }
  166. }
  167. }
  168.  
  169. //displays the array
  170. void Display(float array[][100],int& colSize, int& rowSize)
  171. {
  172. int row=0,col=0;
  173. for(row = 0;row < rowSize;row++)
  174. {
  175. for(col = 0; col<colSize; col++)
  176. {
  177. cout<< array[row,col];
  178. outData<< array[row,col];
  179. }
  180. cout<<endl;
  181. outData<<endl;
  182. }
  183. }
  184.  
  185. //finds the average of the numbers in the array
  186. float Average(float array[][100],int& colSize, int& rowSize)
  187. {
  188.  
  189. int row=0,col=0;
  190. float sum;
  191. for(row = 0;row < rowSize;row++)
  192. {
  193. for(col = 0; col<colSize; col++)
  194. sum = sum + array[row][col];
  195. }
  196.  
  197. return sum / float(row * col);
  198. }
  199.  
  200. //finds the larest number in the array
  201. float Largest(float array[][100],int& colSize, int& rowSize)
  202. {
  203.  
  204. int row=0,col=0;
  205. float large = 0.0;
  206.  
  207. for(row = 0;row < rowSize;row++)
  208. {
  209. for(col = 0; col<colSize; col++)
  210. {
  211. if (array[row][col]> large)
  212. large = array[row][col];
  213. }
  214. }
  215. return large;
  216. }
  217.  
  218. //finds the smallest number in the array
  219. float Smallest(float array[][100],int& colSize, int& rowSize)
  220. {
  221. int row =0,col=0;
  222. float small = 0.0;
  223. for(row = 0;row < rowSize;row++)
  224. {
  225. for(col = 0; col<colSize; col++)
  226. {
  227. if (array[row][col]< small)
  228. small = array[row][col];
  229. }
  230. }
  231. return small;
  232. }
  233.  
  234. //finds the values in between two numbers
  235. int Between(float array[][100],int& colSize, int& rowSize)
  236. {
  237. int row=0,col=0;
  238. int num1,num2;
  239. int tally =0;
  240. cout<<"Enter the smallest number: "<<endl;
  241. outData<<"Enter the smallest number: "<<endl;
  242. cin>>num1>>endl;
  243. cout<<"Enter the larger number: "<<endl;
  244. outData<<"Enter the larger number: "<<endl;
  245. cin>>num2>>endl;
  246.  
  247. for(row = 0;row < rowSize;row++)
  248. {
  249. for(col = 0; col<colSize; col++)
  250. {
  251. if((array[row][col]>num1)&&(array[row][col]<num2))
  252. tally++;
  253. }
  254. }
  255.  
  256. return tally;
  257. }
  258.  
  259. //searches the array for a value
  260. int Search(float array[][100],int& colSize, int& rowSize)
  261. {
  262. float target = 0;
  263. bool done = 0;
  264. int row=0,col=0,tally;
  265. cout<<"Enter target number: "<<endl;
  266. outData<<"Enter target number: "<<endl;
  267. cin>>target;
  268.  
  269. while(row<rowSize)
  270. {
  271. while(col<colSize)
  272. {
  273. if(array[row][col] == target)
  274. {
  275. tally++;
  276. col++;
  277. }
  278. }
  279. row++;
  280. }
  281. return tally;
  282. }
Last edited by alc6379; Jan 31st, 2005 at 9:35 pm. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help with Error message

 
0
  #2
Jan 31st, 2005
If you're going to do using namespace std, put it immediately after your includes. As it is, you're using ifstream and ofstream without qualifying the namespace.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 15
Reputation: Foxtildawn is an unknown quantity at this point 
Solved Threads: 0
Foxtildawn Foxtildawn is offline Offline
Newbie Poster

Re: Help with Error message

 
0
  #3
Jan 31st, 2005
thanks but now im getting this error about by fuctions:

error C2664: 'Load' : cannot convert parameter 1 from 'float' to 'float [][100]'
There is no context in which this conversion is possible

any ideas?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help with Error message

 
0
  #4
Jan 31st, 2005
>error C2664: 'Load' : cannot convert parameter 1 from 'float' to 'float [][100]'
You're passing a float but the function expects a two dimensional array of floats. The fix for this should be obvious.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC