-1

How do I instead of entering a name, enters 'quit' and it will close the program?

string name;

cout << "Enter a name: "<< " "; 
std::getline (std::cin,input);
input[0] = toupper (input[0]);
johnsyweb
  • 136,902
  • 23
  • 188
  • 247
V Kid
  • 117
  • 4
  • 12
  • possible duplicate of [How to enter 'quit' to close progrom](http://stackoverflow.com/questions/19276439/how-to-enter-quit-to-close-progrom) – johnsyweb Oct 09 '13 at 16:10

1 Answers1

0

C++ is rusty something like this...

string name;

cout << "Enter a name: "<< " "; 
std::getline (std::cin,input);
input[0] = toupper (input[0]);
if (input[0] == 'quit')
   {
      std::exit;
   }

Using Visual C++

 #include "stdafx.h"
 #include <iostream>
 #include <string>

 using namespace std;

 int main(int argc, char* argv[])
 {

     string strinput;

     while (strinput != "quit")
     {
         cout << "Enter a name: " << endl;
         cin.clear();
         cin >> strinput;

         if(strinput =="quit")
         exit(0);

     }  
    return 0;   
}
RizcoTech
  • 265
  • 1
  • 3
  • 12
  • if (input[0] == "quit") this part have error, operand types are incompatiable. "char" and "const char*" – V Kid Oct 07 '13 at 19:29
  • try above. Are you just trying to get rid of the "Press Any key" or is the edited code working? – RizcoTech Oct 07 '13 at 20:13
  • The code you provided is not working, when i type 'quit' it does not close program. – V Kid Oct 07 '13 at 20:54
  • I basically is doing this in a do while loop to repeat program over and over but upon entering 'quit' the progrom should quit and close. – V Kid Oct 07 '13 at 20:57