I need help with the errors I developed with C++

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2009
Posts: 4
Reputation: jcwm249 is on a distinguished road 
Solved Threads: 0
jcwm249 jcwm249 is offline Offline
Newbie Poster

I need help with the errors I developed with C++

 
1
  #1
Jul 4th, 2009
Ok I am trying to write up a data system on C++ so that when i enter in 1-10 i can choose what i want to do....but I keep on getting errors...and the people i already entered in at the bottom (the void add_record) i dont think it correct because there are about 5 of them. please help....the errors will be at the bottom



  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. void DisplayMenu();
  9. int GetChoice();
  10. bool Confirm();
  11. void ProcessChoice(int);
  12.  
  13.  
  14.  
  15. int main()
  16. {
  17. int choice;
  18. bool quit = false;
  19. do
  20. {
  21. DisplayMenu();
  22. choice = GetChoice();
  23. if ( choice == 0 )
  24. {
  25. if (Confirm())
  26. quit = true;
  27. }
  28. else
  29. ProcessChoice(choice);
  30.  
  31. }while (!quit);
  32.  
  33. return 0;
  34. }
  35.  
  36. void DisplayMenu()
  37. {
  38. cout << "1) Enter new patient\n";
  39. cout << "2) List all smokers\n";
  40. cout << "3) List all Male smokers\n";
  41. cout << "4) List all Female smokers\n";
  42. cout << "5) List all with risk factor greater than 5\n";
  43. cout << "6) List all with risk factor less than 5\n";
  44. cout << "7) Search by SS number\n";
  45. cout << "8) List all by an age\n";
  46. cout << "9) List all with HBP and HFD\n";
  47. cout << "10) List Counts of Smokers, HFD, and HBP\n";
  48. cout << "0) Exit\n";
  49. }
  50.  
  51. int GetChoice()
  52. {
  53. int choice;
  54. cout << " Enter a choice ";
  55. cin >> choice;
  56. return choice;
  57. }
  58.  
  59. bool Confirm()
  60. {
  61. char choice = 'N';
  62. bool rsp = false;
  63. bool done = false;
  64. do
  65. {
  66. cout<<" Are you sure to quit (Y/N)? ";
  67. cin >> choice;
  68. choice = toupper (choice);
  69. if (choice == 'Y')
  70. rsp = true;
  71.  
  72. if (choice == 'Y' || choice == 'N')
  73. done = true;
  74. else
  75. done = false;
  76.  
  77. }while (!done);
  78.  
  79. return rsp;
  80. }
  81. void ProcessChoice(int c)
  82. {
  83.  
  84. switch (c)
  85. {
  86.  
  87. case 1:
  88. void add_Record()
  89. {
  90. ofstream outFile;
  91. outFile.open ("records.dat", ios::app);
  92.  
  93.  
  94. string name;
  95. char gender;
  96. int age;
  97. int ss;
  98. int smoke;
  99. int HBP;
  100. int HFD;
  101. int points;
  102.  
  103. cout << "Name: ";
  104. cin >> name;
  105. cout << "Gender: ";
  106. cin >> gender;
  107. cout << "Age: ";
  108. cin >> age;
  109. cout << "SSN: ";
  110. cin >> ss;
  111. cout << "Smoke: ";
  112. cin >> smoke;
  113. cout << "HBP (0/1):";
  114. cin >> HBP;
  115. cout << "HFD (0/1):";
  116. cin >> HFD;
  117. cout << "points (0/1):";
  118. cin >> points;
  119.  
  120. outFile << name <<",";
  121. outFile << gender <<" ";
  122. outFile << age <<" ";
  123. outFile << ss <<" ";
  124. outFile << smoke <<" ";
  125. outFile << HBP <<" ";
  126. outFile << HFD <<" ";
  127. outFile << points << endl;
  128. outFile.close();
  129. return;
  130. }
  131. break;
  132.  
  133.  
  134. case 2:
  135. void get_Record()
  136. {
  137. ifstream inFile;
  138.  
  139. inFile.open ("records.dat", ios_base::in);
  140. string name;
  141. char gender;
  142. int age;
  143. int ss;
  144. int smoke;
  145. int HBP;
  146. int HFD;
  147. int points;
  148.  
  149. if (inFile.is_open())
  150. {
  151. getline(inFile, name, ',');
  152.  
  153. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  154.  
  155. cout << name <<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", ";
  156. if (smoke == 1)
  157. cout <<"Smoker, ";
  158. else
  159. cout <<"Non Smoker, ";
  160.  
  161. system ("pause");
  162. }
  163. else
  164. cout<<"File could not be opened.\n";
  165. inFile.close();
  166. return;
  167. }
  168.  
  169. break;
  170. case 3:
  171. void get_Record()
  172. {
  173.  
  174. ifstream inFile;
  175. inFile.open ("records.dat", ios::in);
  176. string name;
  177. char gender;
  178. int age;
  179. int ss;
  180. int smoke;
  181. int HBP;
  182. int HFD;
  183. int points;
  184.  
  185. if (inFile.is_open())
  186. {
  187. getline(inFile, name, ',');
  188.  
  189. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  190.  
  191. cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", ";
  192. if (smoke ==1 && gender == 'M')
  193. cout <<"Smoker, ";
  194. else
  195. cout <<"Non Smoker, ";
  196.  
  197. system ("pause");
  198. }
  199. else
  200. cout<<"File could not be opened.\n";
  201. }
  202.  
  203. break;
  204. case 4:
  205. void get_Record()
  206. {
  207.  
  208. ifstream inFile;
  209. inFile.open ("records.dat", ios::in);
  210. string name;
  211. char gender;
  212. int age;
  213. int ss;
  214. int smoke;
  215. int HBP;
  216. int HFD;
  217. int points;
  218.  
  219. if (inFile.is_open())
  220. {
  221. getline(inFile, name, ',');
  222.  
  223. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  224.  
  225. cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", ";
  226. if (smoke ==1 && gender == 'F')
  227. cout <<"Smoker, ";
  228. else
  229. cout <<"Non Smoker, ";
  230. system ("pause");
  231. }
  232. else
  233. cout<<"File could not be opened.\n";
  234. }
  235.  
  236. break;
  237. case 5:
  238. void get_Record()
  239. {
  240.  
  241. ifstream inFile;
  242. inFile.open ("records.dat", ios::in);
  243. string name;
  244. char gender;
  245. int age;
  246. int ss;
  247. int smoke;
  248. int HBP;
  249. int HFD;
  250. int points;
  251.  
  252. if (inFile.is_open())
  253. {
  254. getline(inFile, name, ',');
  255.  
  256. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  257.  
  258. cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", ";
  259. if (points >= 5)
  260. cout <<"Risk Factors Greater Than 5, ";
  261. else
  262. cout <<"Non Risk Factors Greater Than 5, ";
  263.  
  264. system ("pause");
  265. }
  266. else
  267. cout<<"File could not be opened.\n";
  268.  
  269. }
  270.  
  271. break;
  272. case 6:
  273. void get_Record()
  274. {
  275.  
  276. ifstream inFile;
  277. inFile.open ("records.dat", ios::in);
  278. string name;
  279. char gender;
  280. int age;
  281. int ss;
  282. int smoke;
  283. int HBP;
  284. int HFD;
  285. int points;
  286.  
  287. if (inFile.is_open())
  288. {
  289. getline(inFile, name, ',');
  290.  
  291. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  292.  
  293. cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", ";
  294. if (points <= 5)
  295. cout <<"Risk Factors Less Than 5, ";
  296. else
  297. cout <<"Non Risk Factors Less Than 5, ";
  298.  
  299. system ("pause");
  300. }
  301. else
  302. cout<<"File could not be opened.\n";
  303.  
  304. }
  305. break;
  306. case 7:
  307. void get_Record()
  308. {
  309. ifstream inFile;
  310. inFile.open ("records.dat", ios::in);
  311. string name;
  312. char gender;
  313. int age;
  314. int ss;
  315. int smoke;
  316. int HBP;
  317. int HFD;
  318. int points;
  319.  
  320. if (inFile.is_open())
  321. {
  322. getline(inFile, name, ',');
  323.  
  324. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  325.  
  326. cout<<"SS# "<<ss<<", "<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", ";
  327.  
  328. system ("pause");
  329. }
  330. else
  331. cout<<"File could not be opened.\n";
  332.  
  333. }
  334.  
  335. break;
  336. case 8:
  337. void get_Record()
  338. {
  339.  
  340. ifstream inFile;
  341. inFile.open ("records.dat", ios::in);
  342. string name;
  343. char gender;
  344. int age;
  345. int ss;
  346. int smoke;
  347. int HBP;
  348. int HFD;
  349. int points;
  350. if (inFile.is_open())
  351. {
  352. getline(inFile, name, ',');
  353.  
  354. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  355. cout<<"Age: "<<age<<", "<<name<<", "<<"Gender: "<<gender<<", "<<"SS# "<<ss<<", ";
  356.  
  357. system ("pause");
  358. }
  359. else
  360. cout<<"File could not be opened.\n";
  361. }
  362.  
  363. break;
  364. case 9:
  365. void get_Record()
  366. {
  367. ifstream inFile;
  368. inFile.open ("records.dat", ios::in);
  369. string name;
  370. char gender;
  371. int age;
  372. int ss;
  373. int smoke;
  374. int HBP;
  375. int HFD;
  376. int points;
  377.  
  378. if (inFile.is_open())
  379. {
  380. getline(inFile, name, ',');
  381.  
  382. inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points;
  383.  
  384. cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", ";
  385.  
  386. if (HBP ==1 && HFD == 1)
  387. cout <<"HBP and HFD, ";
  388. else
  389. cout << "No HBP and HFD, ";
  390.  
  391. system ("pause");
  392. }
  393. else
  394. cout<<"File could not be opened.\n";
  395. }
  396.  
  397. break;
  398.  
  399. default:
  400. cout<<"wrong choice!\n";
  401.  
  402. } ;
  403.  
  404. }
  405.  
  406. void add_Record()
  407. {
  408. ofstream outFile;
  409. outFile.open ("records.dat", ios::app);
  410. string name = "Ms. Johnson";
  411. char gender = 'F'
  412. ;
  413. int age = 33;
  414. int ss = 123456788;
  415. int smoke = 0;
  416. int HBP = 0;
  417. int HFD = 1;
  418. int points = 4;
  419.  
  420.  
  421. outFile << name <<",";
  422. outFile << gender <<" ";
  423. outFile << age <<" ";
  424. outFile << ss <<" ";
  425. outFile << smoke <<" ";
  426. outFile << HBP <<" ";
  427. outFile << HFD <<" ";
  428. outFile << points << endl;
  429.  
  430. outFile.close();
  431. return;
  432. }
  433. void add_Record()
  434. {
  435. ofstream outFile;
  436. outFile.open ("records.dat", ios::app);
  437. string name = "Mr. Kime";
  438. char gender = 'M'
  439. ;
  440. int age = 19;
  441. int ss = 123456888;
  442. int smoke = 0;
  443. int HBP = 1;
  444. int HFD = 1;
  445. int points = 4;
  446.  
  447.  
  448. outFile << name <<",";
  449. outFile << gender <<" ";
  450. outFile << age <<" ";
  451. outFile << ss <<" ";
  452. outFile << smoke <<" ";
  453. outFile << HBP <<" ";
  454. outFile << HFD <<" ";
  455. outFile << points << endl;
  456.  
  457. outFile.close();
  458. return;
  459. }
  460. void add_Record()
  461. {
  462. ofstream outFile;
  463. outFile.open ("records.dat", ios::app);
  464. string name = "Mrs. White";
  465. char gender = 'F'
  466. ;
  467. int age = 50;
  468. int ss = 124356788;
  469. int smoke = 0;
  470. int HBP = 1;
  471. int HFD = 1;
  472. int points = 6;
  473.  
  474.  
  475. outFile << name <<",";
  476. outFile << gender <<" ";
  477. outFile << age <<" ";
  478. outFile << ss <<" ";
  479. outFile << smoke <<" ";
  480. outFile << HBP <<" ";
  481. outFile << HFD <<" ";
  482. outFile << points << endl;
  483.  
  484. outFile.close();
  485. return;
  486. }
  487. void add_Record()
  488. {
  489. ofstream outFile;
  490. outFile.open ("records.dat", ios::app);
  491. string name = "Mr. Long";
  492. char gender = 'M'
  493. ;
  494. int age = 27;
  495. int ss = 121116788;
  496. int smoke = 1;
  497. int HBP = 1;
  498. int HFD = 0;
  499. int points = 8;
  500.  
  501.  
  502. outFile << name <<",";
  503. outFile << gender <<" ";
  504. outFile << age <<" ";
  505. outFile << ss <<" ";
  506. outFile << smoke <<" ";
  507. outFile << HBP <<" ";
  508. outFile << HFD <<" ";
  509. outFile << points << endl;
  510.  
  511. outFile.close();
  512. return;
  513. }
  514. void add_Record()
  515. {
  516. ofstream outFile;
  517. outFile.open ("records.dat", ios::app);
  518. string name = "Mrs. Hughes";
  519. char gender = 'F'
  520. ;
  521. int age = 43;
  522. int ss = 123452768;
  523. int smoke = 1;
  524. int HBP = 1;
  525. int HFD = 1;
  526. int points = 10;
  527.  
  528.  
  529. outFile << name <<",";
  530. outFile << gender <<" ";
  531. outFile << age <<" ";
  532. outFile << ss <<" ";
  533. outFile << smoke <<" ";
  534. outFile << HBP <<" ";
  535. outFile << HFD <<" ";
  536. outFile << points << endl;
  537.  
  538. outFile.close();
  539. return;
  540. }
  541. void add_Record()
  542. {
  543. ofstream outFile;
  544. outFile.open ("records.dat", ios::app);
  545. string name = "Ms. Flinstone";
  546. char gender = 'F'
  547. ;
  548. int age = 17;
  549. int ss = 124533248;
  550. int smoke = 0;
  551. int HBP = 0;
  552. int HFD = 1;
  553. int points = 2;
  554.  
  555.  
  556. outFile << name <<",";
  557. outFile << gender <<" ";
  558. outFile << age <<" ";
  559. outFile << ss <<" ";
  560. outFile << smoke <<" ";
  561. outFile << HBP <<" ";
  562. outFile << HFD <<" ";
  563. outFile << points << endl;
  564.  
  565. outFile.close();
  566. return;
  567. }





here are the errors:

1>main.cpp(99) : error C2601: 'add_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(146) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(182) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(216) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(249) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(284) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(318) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(348) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(376) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(444) : error C2084: function 'void add_Record(void)' already has a body
1>main.cpp(14) : see previous definition of 'add_Record'

1>Final Project 1 - 10 error(s), 0 warning(s)




any help would be very nice!!
Last edited by Ancient Dragon; Jul 4th, 2009 at 9:04 pm. Reason: add line numbers
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,678
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: I need help with the errors I developed with C++

 
0
  #2
Jul 4th, 2009
line 88 of the code you posted: You can not code a function inside another function. Write that function outside any other function then just call it on line 88.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: jcwm249 is on a distinguished road 
Solved Threads: 0
jcwm249 jcwm249 is offline Offline
Newbie Poster

Re: I need help with the errors I developed with C++

 
0
  #3
Jul 4th, 2009
Oh ok...I took out the void part of the beginning of the cases and added void get_Record(); and void add_Record(); to the very beginning, but it still left me with the last error:

1>(437) : error C2084: function 'void add_Record(void)' already has a body
1>(7) : see previous definition of 'add_Record'
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,678
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: I need help with the errors I developed with C++

 
0
  #4
Jul 4th, 2009
That error message is quite explicit -- you have coded that function more than once.
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


Views: 276 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC