Validating my date string & exit process

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
/*
 * book.cpp
 *
 *Simple program for storing array of book titles and published dates
 *
 *  Created on: Oct 9, 2010
 *      Author: Alpha
 */
#include <iostream>
#include <string>
using namespace std;
//declaration section
class book
{
private:
	string bookTitle;
	string publishedDate;
public:
	void booktitles (string);
	void date (string);
	void printbook ();
};
void book::booktitles(string bookName)
{
	bookTitle = bookName;
	cout << "You have entered " << bookTitle << " as your book title" << endl;
}
void book::date(string date)
{
	publishedDate = date;
	cout << "You have entered " << publishedDate << " as your book published date" << endl;
}
void book::printbook()
{
	//cout << bookTitle << "published in " << publishedDate << endl;
}
int main ()
{
	const int SIZE = 10;
   	string titles[SIZE];
   	string dates[SIZE];
    int x;
    book publishedTitle;

		for (x = 0; x < SIZE; ++x)
   {
    cout << "Please enter the book title, press 99 to print previous records or type exit to quit ";
	getline (cin, titles[x]);
	if (titles == 00)
		{
			cout << "Bye Bye";
		}
	else
	publishedTitle.booktitles (titles[x]);
	cout << "Please enter published date in DD/MM/YYYY format " << endl;
	getline (cin, dates[x]);
	publishedTitle.date (dates[x]);
 }	
return 0;
}


Can date that are input in string be validated?

1
2
3
4
5
6
if (titles == 00)
		{
			cout << "Bye Bye";
		}
	else
	publishedTitle.booktitles (titles[x]);


For above portion of code it doesn't work but there no error during compiled.
What do you mean by titles == 00? On a separate note, remember that 00 means 0 in octal. In that case, it means the same number, but if you said 010, for instance, it would actually mean decimal 8.
Hi Filipe, I actually wanted a way to exit from the program. So for example if i type in 00, the program will display Bye Bye then exit.
"00" is a string. 00 is a number. But why are you asking for 10 titles and dates when you only have one book object to fill?
If i use titles == "00" i get this error "comparison between distinct pointer types 'std::string*' and 'const char*' lacks a cast".

It will keep going in a for loop till 10 titles / dates is entered.
titles is a pointer to the first element of the array. You probably mean titles[x].

It will keep going in a for loop till 10 titles / dates is entered.

Yes, but you're overwriting them all because you only have one book object to store them in. You should be using a container or an array of book objects.
Hi filipe, sorry but i getting confuse.
You only instantiate one object of type book (publishedTitle). Then you repeatedly fill the same object ten times with different values. Each time around, you just overwrite what was previously stored in publishedTitle.
Topic archived. No new replies allowed.