5 Replies - 971 Views - Last Post: 22 October 2009 - 10:49 AM Rate Topic: -----

#1 JCollins8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-September 09

do...while question

Post icon  Posted 22 October 2009 - 10:38 AM

#include <iostream>
#include <string>

using namespace std;

void menu()
{
  cout << "**********" << endl;
  cout << "(F) Find" << endl;
  cout << "(I) Insert" << endl;
  cout << "(D) Delete" << endl;
  cout << "(U) Update" << endl;
  cout << "(Q) Quit" << endl;
  cout << "**********" << endl;
  cout << endl;
  cout << endl;
  cout << endl;
  cout << "Please select using a letter ==> ";
}

void sys()
{
  system("clear");
}

int main()
{
  char choice;

  sys();

  do
  {
   menu();
   cin >> choice;

   if(choice == 'F' || choice == 'f')
   {
	 sys();
	 cout << "Find works" << endl;
   }
 else if(choice == 'I' || choice == 'i')
   {
	 sys();
	 cout << "Insert works" << endl;
   }
   else if(choice == 'D' || choice == 'd')
   {
	 sys();
	 cout << "Delete works" << endl;
   }
   else if(choice == 'U' || choice == 'u')
   {
	 sys();
	 cout << "Update works" << endl;
   }
   else
   {
	 sys();
	 cout << "Incorrect selection, please try again." << endl;
   }
  } while(choice != 'Q' || choice != 'q');

  system("clear");
  cout << "Program terminated" << endl;

  return 0;
}


I try exiting the loop with Q or q and it keeps looping. Anybody have any ideas what I am doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: do...while question

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: do...while question

Posted 22 October 2009 - 10:40 AM

No, but I'd personally change it to while(true), check Q/q like the rest and simply call break;.
Was This Post Helpful? 0
  • +
  • -

#3 JCollins8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-September 09

Re: do...while question

Posted 22 October 2009 - 10:46 AM

View PostRudiVisser, on 22 Oct, 2009 - 09:40 AM, said:

No, but I'd personally change it to while(true), check Q/q like the rest and simply call break;.


I tried that. keeps looping...
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: do...while question

Posted 22 October 2009 - 10:48 AM

Errr, is it catching the other keys??
Was This Post Helpful? 0
  • +
  • -

#5 JCollins8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-September 09

Re: do...while question

Posted 22 October 2009 - 10:48 AM

View PostJCollins8, on 22 Oct, 2009 - 09:46 AM, said:

View PostRudiVisser, on 22 Oct, 2009 - 09:40 AM, said:

No, but I'd personally change it to while(true), check Q/q like the rest and simply call break;.


I tried that. keeps looping...




I forgot a semicolon at the end. Thank you very much, it works.
Was This Post Helpful? 0
  • +
  • -

#6 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: do...while question

Posted 22 October 2009 - 10:49 AM

Cool stuff, no problem :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1