Return value not working

I have a code in here that u will multiply the number of seat and the number of ticket.
i think i got the correct return value but it's still not working when i times it it always = 0
need help thx



#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>

int getBill(int seat);
int getPos(char seat);
#define tcktsize 4;
using namespace std;
using std::ofstream;


void display(char, int);
int area(char seatchoice);
struct ticket
{
char ans;
char seatnum;
char seatchoice[20];
float bill;
float seat;
char pos;
};

int main()
{
input:

ticket rsrve;


for(int i=0; i<4; i++)


do {





cout<<setw(50)<<"Welcome to One World Ticket"<<endl
<<setw(46)<<"Reservation System"<<endl;

cout << "How many Ticket(s) would you like to reserve?: ";
cin >> rsrve.seatnum;
cout << "Select Seating Areas: ";
cout << "[FS]-Front Seats\n [LBS]-Lower Box Seats\n [UBS]-Upper Box Seats\n [GPS]-General Patronage: \nEnter: ";
cin>>rsrve.seatchoice;
cout<<endl;
if (rsrve.seatchoice,20 == 'FS' || rsrve.seatchoice,20 == 'fs'
&& rsrve.seatchoice,20 == 'lbs' || rsrve.seatchoice,20 == 'LBS'
&& rsrve.seatchoice,20 == 'ubs' || rsrve.seatchoice,20 == 'UBS'
&& rsrve.seatchoice,20 == 'gps' || rsrve.seatchoice,20 == 'GPS')


cout << "\nInvalid Input. Please try again. ";

else{


cout<< "Reserved Number of Tickets: " << rsrve.seatnum;
rsrve.pos=getPos(rsrve.seat);
cout<< "\nSeating Area is: " << rsrve.seatchoice[20];
cout<<endl;
rsrve.bill=getBill(rsrve.seat);
cout<< "Your Total Bill is: " <<rsrve.bill*rsrve.seatnum;
cout << endl << endl;
display ('=', 20);
cout << "\nThank you for patronizing One World Ticket reservation system!" << endl;
cout << "Input Another Transaction (Y/N)?\n";
cin>> rsrve.ans;
}



}while(rsrve.ans=='y');
{
system("cls");
goto input;
}
while(rsrve.ans=='n')
{
cout<<"Thank you!";
}

for(int i=0;i<4;i++)
{
ofstream fout;
fout.open("f:\myfiles\sample1.txt");
fout<<rsrve.seatchoice;
fout<<rsrve.seatnum;
fout.close();
}
system("pause>0");
return 0;
}





void display(char ch, int n)
{
for(int i=0; i<n; i++)
cout << ch; cout << endl;
}


int getBill(int seat)
{
int b=0;

if(seat=='FS'||seat=='fs')
b=15000;
if(seat=='LBS'||seat=='lbs')
b=10000;
if(seat=='UBS'||seat=='ubs')
b=5000;
if(seat=='GPS'||seat=='gps')
b=1500;

return b;
}

int getPos(char seatchoice)
{
int p=0;

if(seatchoice=='FS'||seatchoice=='fs')
cout<<"Your Position is Front Seats";
if(seatchoice=='LBS'||seatchoice=='lbs')
cout<<"Your Position is Lower Box Seats";
if(seatchoice=='UBS'||seatchoice=='ubs')
cout<<"Your Position is Upper Box Seats";
if(seatchoice=='GPS'||seatchoice=='gps')
cout<<"Your Position is General Patronage Seats";

return p;
}
1
2
3
4
if (rsrve.seatchoice,20 == 'FS' || rsrve.seatchoice,20 == 'fs'
&& rsrve.seatchoice,20 == 'lbs' || rsrve.seatchoice,20 == 'LBS'
&& rsrve.seatchoice,20 == 'ubs' || rsrve.seatchoice,20 == 'UBS'
&& rsrve.seatchoice,20 == 'gps' || rsrve.seatchoice,20 == 'GPS')


It's interesting that this compiles for you. Apostrophes are used for single characters, not strings.
And this is not how you compare C strings. (Do you even know what the , does in your case?)
And because you're a C++ programmer you should use C++ strings (std::string) instead of C strings.

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
#include <string>

// ...

struct ticket
{
    char ans;
    char seatnum;
    std::string seatchoice;
    float bill;
    float seat;
    char pos;
};

// ...

std::getline(std::cin, rsrve.seatchoice);

if (rsrve.seatchoice != "fs" && rsrve.seatchoice != "FS"
    && rsrve.seatchoice != "lbs" && rsrve.seatchoice != "LBS"
    && rsrve.seatchoice != "ubs" && rsrve.seatchoice != "UBS"
    && rsrve.seatchoice != "gps" && rsrve.seatchoice != "GPS")
{
    cout << "\nInvalid Input. Please try again. ";
}
still not working :(
can you put the whole code because when i put it. it still got underline on it
I just put this in a compiler and the error list is massive. You need to sort out all the erros (They are fairly self explanatory) and all the warnings. Make sure you're compiling with pedantic errors on.
but i didn't get it pls help me i need it :(
Here's the output and question

Create a program that will reserve a tickets for a concert of an International Artist. The program must correspond with the following requirements:
o It have the following seating areas with their respective prices such as: Front seats – 15,000.00, lower box seats - 10,000.00, Upper box seats – 5,000.00, General Patronage seats – 1,500.00.
o It must produce an accurate computation of the bills and shows the reserved seat numbers.


Sample Output:

Welcome to One World Ticket
Reservation System

How many ticket(s) would you like to reserve? : 2
Select Seating Area (FS – Front Seats, LBS – Lower Box Seats, UBS, Upper Box Seats, GPS – General Patronage Seats) : FS

= = = = = = = = = = = = = = =

Reserved number of tickets : 2
Seating Area is Front Seats
Your total bill is Php 30,000.00

Thank you for patronizing One World Ticket reservation system!
Input Another Transaction (Y/N)? Y
and my code is here and not working :(

#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>

int getBill(int seat);
int getPos(char seat);
#define tcktsize 4;
using namespace std;
using std::ofstream;


void display(char, int);
int area(char seatchoice);
struct ticket
{
char ans;
char seatnum;
char seatchoice[20];
float bill;
float seat;
char pos;
};

int main()
{
input:

ticket rsrve;


for(int i=0; i<4; i++)


do {





cout<<setw(50)<<"Welcome to One World Ticket"<<endl
<<setw(46)<<"Reservation System"<<endl;

cout << "How many Ticket(s) would you like to reserve?: ";
cin >> rsrve.seatnum;
cout << "Select Seating Areas: ";
cout << "[FS]-Front Seats\n [LBS]-Lower Box Seats\n [UBS]-Upper Box Seats\n [GPS]-General Patronage: \nEnter: ";
cin>>rsrve.seatchoice;
cout<<endl;
if (rsrve.seatchoice,20 == 'FS' || rsrve.seatchoice,20 == 'fs'
&& rsrve.seatchoice,20 == 'lbs' || rsrve.seatchoice,20 == 'LBS'
&& rsrve.seatchoice,20 == 'ubs' || rsrve.seatchoice,20 == 'UBS'
&& rsrve.seatchoice,20 == 'gps' || rsrve.seatchoice,20 == 'GPS')


cout << "\nInvalid Input. Please try again. ";

else{


cout<< "Reserved Number of Tickets: " << rsrve.seatnum;
rsrve.pos=getPos(rsrve.seat);
cout<< "\nSeating Area is: " << rsrve.seatchoice[20];
cout<<endl;
rsrve.bill=getBill(rsrve.seat);
cout<< "Your Total Bill is: " <<rsrve.bill*rsrve.seatnum;
cout << endl << endl;
display ('=', 20);
cout << "\nThank you for patronizing One World Ticket reservation system!" << endl;
cout << "Input Another Transaction (Y/N)?\n";
cin>> rsrve.ans;
}



}while(rsrve.ans=='y');
{
system("cls");
goto input;
}
while(rsrve.ans=='n')
{
cout<<"Thank you!";
}

for(int i=0;i<4;i++)
{
ofstream fout;
fout.open("f:\myfiles\sample1.txt");
fout<<rsrve.seatchoice;
fout<<rsrve.seatnum;
fout.close();
}
system("pause>0");
return 0;
}





void display(char ch, int n)
{
for(int i=0; i<n; i++)
cout << ch; cout << endl;
}


int getBill(int seat)
{
int b=0;

if(seat=='FS'||seat=='fs')
b=15000;
if(seat=='LBS'||seat=='lbs')
b=10000;
if(seat=='UBS'||seat=='ubs')
b=5000;
if(seat=='GPS'||seat=='gps')
b=1500;

return b;
}

int getPos(char seatchoice)
{
int p=0;

if(seatchoice=='FS'||seatchoice=='fs')
cout<<"Your Position is Front Seats";
if(seatchoice=='LBS'||seatchoice=='lbs')
cout<<"Your Position is Lower Box Seats";
if(seatchoice=='UBS'||seatchoice=='ubs')
cout<<"Your Position is Upper Box Seats";
if(seatchoice=='GPS'||seatchoice=='gps')
cout<<"Your Position is General Patronage Seats";

return p;
}
1) Please use code tags when posting code to make it readable. The more easy it is to read, the more easy it is for us to help you.

2) "not working" is spectacularly unhelpful. What do you mean? Is it failing to compile? Failing to run? Running but producing unexpected results? What errors/unexpected behaviour are you seeing?

Surely you can understand that withholding information from us makes it harder for us to help you?
Last edited on
here sir! thx for the help
running but producing unexpected results it's always = to 0 or random number

#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>

int getBill(char seat);
char getPos(char seatchoice);
#define ticketsize 4;
using namespace std;
using std::ofstream;


void display(char, int);
int area(char seatchoice);
struct ticket
{
char ans;
char seatnum;
char seatchoice[20];
int bill;
int billtotal;
char pos;
char seat;
};

int main()
{
input:

ticket rsrve;


for(int i=0; i<4; i++)


do {



cout<<setw(50)<<"Welcome to One World Ticket"<<endl
<<setw(46)<<"Reservation System"<<endl;

cout << "How many Ticket(s) would you like to reserve?: ";
cin >> rsrve.seatnum;
cout << "Select Seating Areas: ";
cout << "[FS]-Front Seats\n [LBS]-Lower Box Seats\n [UBS]-Upper Box Seats\n [GPS]-General Patronage: \nEnter: ";

for (int x=0; x<2;x++)
{
cin.getline(rsrve.seatchoice, 20);

}
if (rsrve.seatchoice == "FS" || rsrve.seatchoice == "fs"
&& rsrve.seatchoice == "lbs" || rsrve.seatchoice == "LBS"
&& rsrve.seatchoice == "ubs" || rsrve.seatchoice == "UBS"
&& rsrve.seatchoice == "gps" || rsrve.seatchoice == "GPS")


{cout << "\nInvalid Input. Please try again. ";

}else{


cout<< "Reserved Number of Tickets: " << rsrve.seatnum;


cout<< "\nSeating Area is: " << rsrve.seatchoice, 20;


cout<< "\nYour Total Bill is: " << rsrve.seatnum*getBill(rsrve.seat);
cout << endl << endl;
display ('=', 20);
cout << "\nThank you for patronizing One World Ticket reservation system!" << endl;
cout << "Input Another Transaction (Y/N)?\n";
cin>> rsrve.ans;
}



}while(rsrve.ans=='y');
{
system("cls");
goto input;
}
while(rsrve.ans=='n')
{
cout<<"Thank you!";
}

for(int i=0;i<4;i++)
{
ofstream fout;
fout.open("f:\myfiles\sample1.txt");
fout<<rsrve.seatchoice;
fout<<rsrve.seatnum;
fout.close();
}
system("pause>0");
return 0;
}





void display(char ch, int n)
{
for(int i=0; i<n; i++)
cout << ch; cout << endl;
}


int getBill(char seat)
{
int b=0;

if(seat=='FS'||seat=='fs')
b=15000;
if(seat=='LBS'||seat=='lbs')
b=10000;
if(seat=='UBS'||seat=='ubs')
b=5000;
if(seat=='GPS'||seat=='gps')
b=1500;

return b;
}

char getpos(char seatchoice)
{
int p=0;
char choice;
if(seatchoice=='fs'||seatchoice=='FS')
char choice[]="your position is front seats";
if(seatchoice=='lbs'||seatchoice=='LBS')
char choice[]="your position is lower box seats";
if(seatchoice=='ubs'||seatchoice=='UBS')
char choice[]="your position is upper box seats";
if(seatchoice=='gps'||seatchoice=='GPS')
char choice[]="your position is general patronage seats";

return p;
}
Last edited on
Code tags tutorial:
http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
if (rsrve.seatchoice == "FS" || rsrve.seatchoice == "fs"
&& rsrve.seatchoice == "lbs" || rsrve.seatchoice == "LBS"
&& rsrve.seatchoice == "ubs" || rsrve.seatchoice == "UBS"
&& rsrve.seatchoice == "gps" || rsrve.seatchoice == "GPS")


This above doesn't work because seatchoice is a C string and not a C++ string.

1
2
3
char seatchoice[20]; // C string

std::string seatchoice; // C++ string 


You can't compare C strings "naturally" by using the equality operator==.
For them you must use the std::strcmp() function.

I will say again, since you're a C++ programmer, you should just use C++ std::strings.
still not working it say that
Error 1 error LNK2019: unresolved external symbol "char __cdecl getPos(char)" (?getPos@@YADD@Z) referenced in function _main C:\Users\Francis\Documents\Visual Studio 2012\Projects\Project4\Project4\Source1.obj Project4

#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>

int getBill(char seat);
char getPos(char seatchoice);
#define ticketsize 4;
using namespace std;
using std::ofstream;


void display(char, int);
int area(char seatchoice);
struct ticket
{
char ans;
char seatnum;
std::string seatchoice;
int bill;
int billtotal;
char pos;
char seat;
};

int main()
{
input:

ticket rsrve;


for(int i=0; i<4; i++)


do {



cout<<setw(50)<<"Welcome to One World Ticket"<<endl
<<setw(46)<<"Reservation System"<<endl;

cout << "How many Ticket(s) would you like to reserve?: ";
cin >> rsrve.seatnum;
cout << "Select Seating Areas: ";
cout << "[FS]-Front Seats\n [LBS]-Lower Box Seats\n [UBS]-Upper Box Seats\n [GPS]-General Patronage: \nEnter: ";

for (int x=0; x<2;x++)
{
cin>>rsrve.seatchoice;

}
if (rsrve.seatchoice == "FS" || rsrve.seatchoice == "fs"
&& rsrve.seatchoice == "lbs" || rsrve.seatchoice == "LBS"
&& rsrve.seatchoice == "ubs" || rsrve.seatchoice == "UBS"
&& rsrve.seatchoice == "gps" || rsrve.seatchoice == "GPS")


{cout << "\nInvalid Input. Please try again. ";

}else{


cout<< "Reserved Number of Tickets: " << rsrve.seatnum;


rsrve.seatchoice[20]=getPos(rsrve.seatchoice[20]);
cout<< "\nSeating Area is: " << rsrve.pos;
rsrve.bill=getBill(rsrve.seat);

//yung getBill muna yung icheck
cout<< "\nYour Total Bill is: " << rsrve.seatnum*rsrve.bill;
cout << endl << endl;
display ('=', 20);
cout << "\nThank you for patronizing One World Ticket reservation system!" << endl;
cout << "Input Another Transaction (Y/N)?\n";
cin>> rsrve.ans;
}



}while(rsrve.ans=='y');
{
system("cls");
goto input;
}
while(rsrve.ans=='n')
{
cout<<"Thank you!";
}
//
//for(int i=0;i<4;i++)
// {
// ofstream fout;
// fout.open("f:\myfiles\sample1.txt");
// fout<<rsrve.seatchoice;
// fout<<rsrve.seatnum;
// fout.close();
//}
system("pause>0");
return 0;
}





void display(char ch, int n)
{
for(int i=0; i<n; i++)
cout << ch; cout << endl;
}


int getBill(char seat)
{
int b=0;


if(seat=='FS'||seat=='fs')
b=15000;
if(seat=='LBS'||seat=='lbs')
b=10000;
if(seat=='UBS'||seat=='ubs')
b=5000;
if(seat=='GPS'||seat=='gps')
b=1500;

return b;
}

//char getpos(char pos)
//{
// int p=0;
// char choice;

//if(pos=='fs'||pos=='fs')
// char choice[]="your position is front seats";
//if(pos=='lbs'||pos=='lbs')
// char choice[]="your position is lower box seats";
//if(pos=='ubs'||pos=='ubs')
// char choice[]="your position is upper box seats";
//if(pos=='gps'||pos=='gps')
// char choice[]="your position is general patronage seats";
//
//return p;
//}
You're not really reading the replies properly, you've been given all the answers already. I suspect you're trying to migrate to C++ from a very different language, and are still missing some key points. I hope you won't be offended by my approach - I've changed your program a bit (see below). First try building and running it it, then compare concepts with what you were trying to do. This may give you some more insight.
You may think the way I've written it is not very good, but I'm just trying to highlight some C++ concepts you're missing, without changing your code too much.

Also don't forget:

format
indent
and there's no way that code up there compiled.

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <algorithm>

#include <cstdlib>
#include <cctype>

using namespace std;

int getBill(int seat);
int getPos(string &seat);

int area(string seatchoice);

struct ticket
{
	string ans;
	unsigned numSeats;
	string seatChoice;
	double bill;
	double seat;
	string pos;
};

enum
{
	GPSPRICE = 1500,
	UBSPRICE = 5000,
	LBSPRICE = 10000,
	FSPRICE  = 15000
};

int main()
{
	string cont = "Y";
	while(toupper(*cont.begin()) == 'Y')
	{
		ticket rsrve;

		cout << endl;
		cout<<setw(50)<<"Welcome to One World Ticket"<<endl
		<<setw(46)<<"Reservation System"<<endl;
		
		cout << "How many Ticket(s) would you like to reserve?: ";
		cin >> rsrve.numSeats;
		cin.clear();
		
		cout << "Select Seating Areas: ";
		string s1("[FS]-Front Seats");
		string s2("[LBS]-Lower Box Seats");
		string s3("[UBS]-Upper Box Seats");
		string s4("[GPS]-General Patronage");
		string s("");
		
		cout << endl;
		cout << s1 << endl;
		cout << s2 << endl;
		cout << s3 << endl;
		cout << s4 << endl;
		
		cout << "Please enter FS, UBS, LBS or GPS" << endl;
		cin >> s;
		cin.clear();
		transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper);
		
		if (s == "FS")
		{
			rsrve.seatChoice = s1;
			rsrve.bill = rsrve.numSeats * FSPRICE;
		}
		else if (s == "LBS")
		{
			rsrve.seatChoice = s2;
			rsrve.bill = rsrve.numSeats * LBSPRICE;
		}
		else if (s == "UBS")
		{
			rsrve.seatChoice = s3;
			rsrve.bill = rsrve.numSeats * UBSPRICE;
		}
		else if (s == "GPS")
		{
			rsrve.seatChoice = s4;
			rsrve.bill = rsrve.numSeats * GPSPRICE;
		}
		else
		{
			cout << "\nInvalid Input. Please try again." << endl;
			continue;
		}
		
		cout << "Reserved Number of Tickets is " 	<< rsrve.numSeats 	<< endl;
		cout << "Seating Area is " 			<< rsrve.seatChoice << endl;
		cout << "Your total bill is " 			<< rsrve.bill 		<< endl;

		cout << "\nThank you for patronizing One World Ticket reservation system!" << endl;
		cout << "Input Another Transaction (Y/N)?" << endl;
		cin >> cont;
		cin.clear();
	}

	system("pause");
	return 0;
}
Thank you very much :)
Why did you delete your posts? You've just ruined the value of this thread as a learning resource for anyone else who wants to read it.
Topic archived. No new replies allowed.