how to call text

here is my coding :

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
using namespace std;

int main()
{
	char code, hall, f;
	int aud;
	float price, g1(char hall, int aud), g2(char hall, int aud);


	cout<<"Film Code T : Ong Bank III (Thai)"<<endl;
	cout<<"Film Code U : Twilight Saga : Eclipse (USA)"<<endl<<endl;

	cout<<"Enter Film Code : ";
	cin>>code;

	if (code == 'T')
	{
		cout<<"\n\nType of Hall : G for Cempaka Gold RM40 \nType of Hall : P for Kenanga Premier RM20"<<endl<<endl;
		cout<<"Enter Hall Type : ";
		cin>>hall;
		cout<<"Enter Audiences Number : ";
		cin>>aud;
		price=g1(hall, aud);
	}

	if (code == 'U')
	{
		cout<<"\n\nType of Hall : G for Anggerik Gold RM40 \nType of Hall : P for Melor Premier RM20"<<endl<<endl;
		cout<<"Enter Hall Type : ";
		cin>>hall;
		cout<<"Enter Audiences Number : ";
		cin>>aud;
		price=g2(hall, aud);
	}


	cout<<"\n\nSTAR ENTERTAINMENT REPORT"<<endl;
	cout<<"##########################"<<endl<<endl;
	cout<<"Film Code         : "<<code<<endl;
	cout<<"Film Title 	  : "<<endl;
	cout<<"Type of Hall      : "<<hall<<endl;
	cout<<"Number of Tickets : "<<aud<<endl;
	cout<<"Total Price (RM)  : "<<price<<endl<<endl;
	cout<<"Thank you. Please come again."<<endl<<endl;

	system("PAUSE");
	return 0;
}


float g1(char a, int c)
{
	float ticket;

	if (a=='G')
	{
		ticket=c*40.00;
	}
	else if (a=='P')
	{
		ticket=c*20;
	}
	else
	{
		cout<<"Wrong input. Try again."<<endl;
	}

	return ticket;
}



float g2(char b, int d)
{
	float ticket;

	if (b=='G')
	{
		ticket=d*40;
	}
	else if (b=='P')
	{
		ticket=d*20;
	}
	else
	{
		cout<<"Wrong input. Try again."<<endl;
	}
	return ticket;
}



my question is, how to call "Film Tittle"..?
i have no idea..:(

erm, do not care about the price stated. hehe
Hi there,

You have hardcoded those movienames into these statements:

11
12
cout<<"Film Code T : Ong Bank III (Thai)"<<endl;
	cout<<"Film Code U : Twilight Saga : Eclipse (USA)"<<endl<<endl;


What if you would create separate strings that hold the title, then you could re-use those strings anywhere else in your code:

1
2
std::string film_t("Ong Bank III (Thai)");
cout<< film_t;


All the best,
NwN
NwN

if i want to use what you have suggest, i must use #include <iomanip> ..?
No, you would have to use #include <string> .

You could also use a regular C-string, but I wouldn't recommend it:

1
2
char film_t[] = "Ong Bank III (Thai)";
cout<< film_t;


All the best,
NwN
Last edited on
You could also hold all the films in an array of strings like this:

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

std::string Movies[] = {
    "Movie 01 Title",
    "Movie 02 Title",
    /* ... */
    "Movie ?? Title"
};

const unsigned int MovieCount = sizeof(Movies) / sizeof(*Movies);
// This will hold how many movies you have stored

float MoviePrices[MovieCount] = {
// If you get an error here it's probably because some movies don't have their price in this list
// So look out and add or remove the missing/extra prices
    50.00f, // Suppose first movie is 50$
    25.00f, // And the second is 25$
    /* etc etc */
    150.00f
};

// To print first film's name:
cout << Movies[0];

// To print last film's name:
cout << Movies[MovieCount-1];

// To print all film's names:

for(unsigned int i = 0; i < MovieCount; ++i)
    cout << Movies[i] << endl;

// To get first movie's price:
cout << MoviePrices[0];

// To print both all film's names and prices:
for(unsigned int i = 0; i < MovieCount; ++i)
    cout << Movies[i] << " " << MoviePrices[i] << endl;
Last edited on
Topic archived. No new replies allowed.