Is there anyway to quit using String name

Is there anyway using string name to quit program.
by using number in string to quit program.
for example :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int const limit=100;
	string name[limit];
cout<<"Enter 00 to terminate."<<endl;
for(i=0; i<limit; i++)
	{

	   cout<<"Enter name: ";
	   cin.ignore();
	   getline(cin,name[i]);
           if(name[i]==00)
           {
              break;
           }
system("Pause")
return 0;
}



for some reasons i know that
if(name[i]==00)
does not match the operand. is there way by using integer in string to quit the program?
Last edited on
name[i] is a string. Thus you need to compare it with a string. "00" rather than 00.
 
if (name[i] == "00")
Last edited on
Note: If you are using a loop, then your
name[i]
will just read the first letter of the string.

Maybe you can try this
1
2
3
4
if (name[i] == "0")
{
     break;
}
@Chervil @Peter87 @magnifz97 thanks for the respond

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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int const limit=100;
	string name[limit];
    int amount[limit];
    int i;

	cout<<"Enter 00 to terminate."<<endl;
	
	for(i=0; i<limit; i++)
	{

	   cout<<"Enter name: ";
	   cin.ignore();
	   getline(cin,name[i]);
	   cout<<"Enter amount: RM ";
	   cin>>amount[limit];
	if (name[i]=="00")
	{
		break;
	}
	}
	
system("Pause");
return 0;
}


I tried but it still prompt me to next line.

this is what i get:

Enter 00 to terminate.
Enter name: Bernard
Enter amount: RM 460
Enter name: 00
Enter amount: RM


@magnifz97 thank you for the suggestion. But i wanted to try by using 00.

Appreciate for the response :)
Hello DesmondLee,

Put the if statement after the getline for name i.e., move lines 23 - 26 to line 21.

Hope that helps,

Andy
Thanks @Handy Andy.. its works :)
Topic archived. No new replies allowed.