whats wrong with this string?
for some reason when i type for i dont feel well it says the else but i want it to say the if.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include "stdafx.h"
#include <string>
#include <iostream>
void skipline();
using namespace std;
int main()
{
int pin;
start:
cout << "please enter 4 digit pin code";
cout << ":";
cin >> pin;
if(pin==0000)
{
skipline();
}
else
{
cout << "incorrect or invalid pin code";
cin.get();
goto start;
}
string s1 ("Hello Master!\n");
string r1;
string r2;
cout << s1;
skipline();
cout << ":";
cin >> r1;
if (r1=="hi")
{
skipline();
cout << "how may i assist you\n";
cout << ":";
cin >> r2;
if(r2=="i dont feel well")
{
cout << "Sure whats wrong?\n";
skipline();
cout << ":";
cin.get();
}
else
{
cout << "sorry i cant";
cin.get();
}
cin.get();
}
cin.get();
}
void skipline()
{
cout << "\n";
}
|
If you're looking for exact text input try this:
|
if (r1.find ("Hi") != string::npos)
|
(Not sure if it'll work though)
Topic archived. No new replies allowed.