1 Replies - 560 Views - Last Post: 24 September 2009 - 08:20 PM Rate Topic: -----

#1 eayah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-September 09

accept string as input then the program checks if the input is in the

Post icon  Posted 24 September 2009 - 08:11 PM

description: accept string as input then the program checks if the input is in the language in c++. There is a menu and either you choose the enter keyword, view and exit. As you input the words, the program will check the words into the program and print the correct words and the error words.


#include <iostream>
using namespace std;


main()
{

int desire;



cout << "			MENU";
cout << " \n";

cout << " 1. Enter keyword (s)";
cout << " \n";

cout << " 2. View keyword (s) ";
cout << " \n";

cout << " 3. Exit";
cout << " \n";

cout << " Enter desired action :  ";
cin >> desire;
cout << " \n";
cout << " \n";


return(0);
}

			if(desire==1){

						choice1();

						main();

			}else if(desire==2){

						choice2();

						main();

			}else if(desire==3){

						main();

						exit(0);

			}else{

						printf("\n Invalid choice.");

						main();

			}

void choice1()

{

			int i;

}

void choice2()

{

}
[code]
void choice3()

{

}
}



Is This A Good Question/Topic? 0
  • +

Replies To: accept string as input then the program checks if the input is in the

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5305
  • View blog
  • Posts: 27,198
  • Joined: 10-May 07

Re: accept string as input then the program checks if the input is in the

Posted 24 September 2009 - 08:20 PM

I don't like to use if statements when you are going to parse the results afterwords anyhow. It's extra & wasted processing in my opinion.

#include <iostream>
using namespace std;

void choice(int opt) {
  if(opt!=3) {
	cout << "The option given was " << opt << endl;
  }
  else {
	cout << "Now exiting...";
	exit(0);
  }
}


bool menu(void) {
  int desire;
  cout << "			MENU";
  cout << " \n";

  cout << " 1. Enter keyword (s)" << endl;
  cout << " 2. View keyword (s) " << endl;
  cout << " 3. Exit" << endl;
  cout << " Enter desired action :  ";
  cin >> desire;
  cout << " \n";
  cout << " \n";
  choice(desire);
  return true;
}
int main(void) {
  while(menu());
  return 0;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1