View Single Post
Join Date: Nov 2008
Posts: 11
Reputation: kitty7 is an unknown quantity at this point 
Solved Threads: 0
kitty7 kitty7 is offline Offline
Newbie Poster

Re: A Puzzling Address Book...

 
0
  #6
Dec 5th, 2008
All right, well, this is almost done. I think. I believe I need some help with my switch structure. I think I am done with the logic of most of the functions. If someone can give me some advice or a push in the right direction, I would really appreciate it. I'm not going to post the function code in this thread because I know this website's policy about free homework, and this project is my homework. i don't want to give someone else the homework for this class. So here is my main function, perhaps someone can see what is wrong with the switch

  1. int main()
  2. {
  3.  
  4. PERSON p;
  5. int mySwitch;
  6. char *lName = "ppppppppppppppppppppppppppppppppp";//I know it looks weird, I'm sorry. I had a warning and so I did this
  7. char *fName = "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL";//to initialize...
  8. char access;
  9.  
  10. cout << "This is an address book that can hold ten people. " << endl;
  11. cout << "Would you like to access the address book? y/n" << endl;
  12. cin >> access;
  13. if(access == 'y')
  14. {
  15. cout << "To enter a contact into the address book, press 1. After you are finished, press 2." << endl;
  16. cout << "To view the entire address book, press 3: " << endl;
  17. cout << "To search the address book by last name, press 4: " << endl;
  18. cout << "To search the address book by last and first name, press 5: " << endl;
  19. cout << "To exit, press any other number. " << endl;
  20. cin >> mySwitch;
  21. while(mySwitch < 6)
  22. {
  23.  
  24. switch(mySwitch)
  25. {
  26. case 1:
  27.  
  28. cout << "Enter the first name: " << endl;
  29. cin.getline(p.firstName, 20);
  30. cout << "Enter the last name: " << endl;
  31. cin.getline(p.lastName, 20);
  32. cout << "Enter the address: " << endl;
  33. cin.getline(p.address, 50);
  34.  
  35. addPerson(p);
  36. cout << "To enter a contact into the address book, press 1. After you are finished, press 2." << endl;
  37. cout << "To view the entire address book, press 3: " << endl;
  38. cout << "To search the address book by last name, press 4: " << endl;
  39. cout << "To search the address book by last and first name, press 5: " << endl;
  40. cout << "To exit, press any other number. " << endl;
  41. cin >> mySwitch;
  42.  
  43. break;
  44.  
  45. case 2:
  46.  
  47. cout << "To view the entire address book, press 3: " << endl;
  48. cout << "To search the address book by last name, press 4: " << endl;
  49. cout << "To search the address book by last and first name, press 5: " << endl;
  50. cout << "To exit, press any other button. " << endl;
  51. cin >> mySwitch;
  52.  
  53. break;
  54.  
  55. case 3:
  56.  
  57. cout << getPerson;
  58. break;
  59.  
  60. case 4:
  61.  
  62. cout << "Please enter the last name of the person you would like to view: " << endl;
  63. cin >> lName;
  64. cout << findPerson(lName, p);
  65.  
  66. break;
  67.  
  68. case 5:
  69.  
  70. cout << "Please enter the last and first names of the person you are searching for. " << endl;
  71. cin >> lName >> fName;
  72. cout << findPerson(lName, fName, p);
  73. break;
  74.  
  75. default:
  76. cout << "Thank you for using the address book." << endl;
  77. exit(0);
  78. break;
  79. }
  80. }
  81. }
  82. else
  83. exit(1);
  84.  
  85. return 0;
  86.  
  87. }

Alright, well, when I run this program, I get five warnings because of stricmp, but I'm not worried about that. What I need to know, is why my switch isn't working. If you need more info to help me figure it out, I will be playing around with it too, so I might be able to tell you more about it in a little while...
Last edited by kitty7; Dec 5th, 2008 at 1:44 am. Reason: lol, forgot to put my snippet in 'code'
Reply With Quote