questions run together and I cant figure out why

// Football Ticket Sales

// designed by Wes Ayala

#include <iostream>
using namespace std;

int main ()
{
double tickets, credits, cost,
name, response;

cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
cout << "Florida State University\n";
cout << " Ticket Information\n";
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";

//get name and credits

cout << "Hello and thank you for using FSU’s Ticket Information service.\nPlease enter your name:";
cin >> name;
cout << "How many Florida State University credits have you earned? ";
cin >> credits;

//figure out how many tickets person is eligible for based on credits
//- note that you need two conditions for each if statement and they both need
//to include the ‘=’ to ensure that the proper range is assessed,
//if you didn’t use ‘=’ then the first range would be 1-29 instead of 0-30

if (credits >= 0 && credits <= 30)
cout << name << ", you are eligible for 2 season tickets.";
else if (credits >= 31 && credits <= 60)
cout << name << ", You are eligible for 4 season tickets.";
else if (credits >=61 && credits <=90)
cout << name << ", You are eligible for 6 season tickets.";
else if ( credits >=91)
cout << name << ", You are eligible for 8 season tickets.";

//find florida residency for price determination

cout << "Are you a Florida resident? (Y)es or (N)";
cin >> response;

//here you need nested if statements, the outer if statement checks
//for residency which determines cost, the inner if statement calculates
//cost and makes sure that the user enters valid information

if (response == 'Y' || response == 'y')
{
cout << "Tickets are $75. How many would you like?";
cin >> tickets;
if (credits >= 0 && credits <= 30 && tickets <= 2)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}
if (credits >= 31 && credits <= 60 && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}
if (credits >= 61 && credits <= 90 && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}
if (credits >= 90 tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}

//this else statement means that none of the above conditions were true
//so they must have entered something invalid, the computer will check each
//if statement and if none are true then it goes to the else statement
else
cout << "I’m sorry but that is not a valid response.";
}
else if (response == 'N' || response == 'n')
{
cout << "Tickets are $95. How many would you like?";
cin >> tickets;
if (credits >= 0 && credits <= 30 && tickets <= 2)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}
if (credits >= 31 && credits <= 60 && tickets <= 4)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}
if (credits >= 61 && credits <=90 && tickets <=6)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}
if (credits >=91 && tickets <=8)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}

else
cout << "I’m sorry but that is not a valid response.";
} // this closes the inner statement
} //this closes the outer statement


//this is the output vvvv

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Florida State University
Ticket Information
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Hello and thank you for using FSUÆs Ticket Information service.
Please enter your name:me
How many Florida State University credits have you earned? Are you a Florida res
ident? (Y)es or (N)Press any key to continue . . .
please use code tags, like so. It makes it easier to read.


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
107
108
109
110
111
112
113
114
115
116
117
118
119
// Football Ticket Sales

// designed by Wes Ayala

#include <iostream>
using namespace std;

int main ()
{
double tickets, credits, cost,
name, response;

cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
cout << "Florida State University\n";
cout << " Ticket Information\n";
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";

//get name and credits

cout << "Hello and thank you for using FSU’s Ticket Information service.\nPlease enter your name:";
cin >> name;
cout << "How many Florida State University credits have you earned? ";
cin >> credits;

//figure out how many tickets person is eligible for based on credits
//- note that you need two conditions for each if statement and they both need
//to include the ‘=’ to ensure that the proper range is assessed,
//if you didn’t use ‘=’ then the first range would be 1-29 instead of 0-30

if (credits >= 0 && credits <= 30)
cout << name << ", you are eligible for 2 season tickets.";
else if (credits >= 31 && credits <= 60)
cout << name << ", You are eligible for 4 season tickets.";
else if (credits >=61 && credits <=90)
cout << name << ", You are eligible for 6 season tickets.";
else if ( credits >=91)
cout << name << ", You are eligible for 8 season tickets.";

//find florida residency for price determination

cout << "Are you a Florida resident? (Y)es or (N)";
cin >> response;

//here you need nested if statements, the outer if statement checks
//for residency which determines cost, the inner if statement calculates
//cost and makes sure that the user enters valid information

if (response == 'Y' || response == 'y')
{
cout << "Tickets are $75. How many would you like?";
cin >> tickets;
if (credits >= 0 && credits <= 30 && tickets <= 2)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}
if (credits >= 31 && credits <= 60 && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}
if (credits >= 61 && credits <= 90 && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}
if (credits >= 90 tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to " << cost;
}

//this else statement means that none of the above conditions were true
//so they must have entered something invalid, the computer will check each
//if statement and if none are true then it goes to the else statement
else
cout << "I’m sorry but that is not a valid response.";
}
else if (response == 'N' || response == 'n')
{
cout << "Tickets are $95. How many would you like?";
cin >> tickets;
if (credits >= 0 && credits <= 30 && tickets <= 2)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}
if (credits >= 31 && credits <= 60 && tickets <= 4)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}
if (credits >= 61 && credits <=90 && tickets <=6)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}
if (credits >=91 && tickets <=8)
{
cost = tickets * 95;
cout << "Your total comes to " << cost;
}

else
cout << "I’m sorry but that is not a valid response.";
} // this closes the inner statement
} //this closes the outer statement


/*this is the output vvvv

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Florida State University
Ticket Information
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Hello and thank you for using FSUÆs Ticket Information service.
Please enter your name:me
How many Florida State University credits have you earned? Are you a Florida res
ident? (Y)es or (N)Press any key to continue . . .*/
You didn't end any of your lines... Is that what you mean by text running together?

You used the \n escape code in lines 13, 14, 15, 16, and 20 but never again. You could either add in \n to the end of your string literals or put a endl into the cout steam buffer.

ex.
1
2
3
4
5
cout << "Whatever \n" << "Something Else \n"; // If you want the escape code style.

//or

cout << "Whatever " << endl << "Something Else " << endl; //If you want the endl way 



Just so you know, your code up there won't actually compile because of line 67... You forgot whatever operator you were going to use.

Also you made your responses all double variables. You realize that you are asking for answers in strings right? That will automatically terminate your program if someone doesn't put a double in as a response to for example: what is your name?

I dunno about you but my name is not of type double...

Good luck,
Sean
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
107
108
109
110
111
// Football Ticket Sales

// designed by Wes Ayala

#include <iostream>
#include <string>
using namespace std;

int main ()
{
	
	tickets, 
	credits, 
	cost,
	name, 
	response;

cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
cout << "Florida State University\n";
cout << " Ticket Information\n";
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";

//get name and credits

cout << "Hello and thank you for using FSU’s Ticket Information service.\nPlease enter your name:\n";
cin >> name;
cout << "How many Florida State University credits have you earned? \n";
cin >> credits;

//figure out how many tickets person is eligible for based on credits
//- note that you need two conditions for each if statement and they both need
//to include the ‘=’ to ensure that the proper range is assessed,
//if you didn’t use ‘=’ then the first range would be 1-29 instead of 0-30

if (credits >= 0 && credits <= 30)
cout << name << ", you are eligible for 2 season tickets. \n";
else if (credits >= 31 && credits <= 60)
cout << name << ", You are eligible for 4 season tickets. \n";
else if (credits >=61 && credits <=90)
	cout << name << ", You are eligible for 6 season tickets. \n";
else if ( credits >=91)
	cout << name << ", You are eligible for 8 season tickets. \n";

//find florida residency for price determination

cout << "Are you a Florida resident? (Y)es or (N) \n";
cin >> response;

//here you need nested if statements, the outer if statement checks
//for residency which determines cost, the inner if statement calculates
//cost and makes sure that the user enters valid information

if (response == 'Y' || response == 'y')
{
cout << "Tickets are $75. How many would you like? \n";
cin >> tickets;
if (credits >= 0 && credits <= 30 && tickets <= 2)
{
cost = tickets * 75;
cout << "Your total comes to \n" << cost;
}
if (credits >= 31 && credits <= 60 && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to \n" << cost;
}
if (credits >= 61 && credits <= 90 && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to \n" << cost;
}
if (credits >= 90  && tickets <= 4)
{
cost = tickets * 75;
cout << "Your total comes to \n" << cost;
}
//this else statement means that none of the above conditions were true
//so they must have entered something invalid, the computer will check each
//if statement and if none are true then it goes to the else statement
else
cout << "I’m sorry but that is not a valid response. \n";
}
else if (response == 'N' || response == 'n')
{
cout << "Tickets are $95. How many would you like? \n";
cin >> tickets;
if (credits >= 0 && credits <= 30 && tickets <= 2)
{
cost = tickets * 95;
cout << "Your total comes to \n" << cost;
}
if (credits >= 31 && credits <= 60 && tickets <= 4)
{
cost = tickets * 95;
cout << "Your total comes to \n" << cost;
}
if (credits >= 61 && credits <=90 && tickets <=6)
{
cost = tickets * 95;
cout << "Your total comes to \n" << cost;
}
if (credits >=91 && tickets <=8)
{
cost = tickets * 95;
cout << "Your total comes to \n" << cost;
}

else
cout << "I’m sorry but that is not a valid response. \n";
} // this closes the inner statement
} //this closes the outer statement 




Thanks Sean. This is literally my first program ever and my first time coming to cplusplus.com for help. I believe I fixed \n escape code and added the #include <string> and finished my operation on line 67 which is now on line 72 I believe. I'm still getting this output though. any more suggestions.

thanks again,
Wes



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Florida State University
 Ticket Information
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Hello and thank you for using FSUÆs Ticket Information service.
Please enter your name:me
How many Florida State University credits have you earned? Are you a Florida res
ident? (Y)es or (N)Press any key to continue . . .
Yeah, what I was talking about your variable declarations at the beginning of int main()

1
2
3
4
int main ()
{
double tickets, credits, cost,
name, response;


What you are doing here is declaring all of your variables of type double.

If you don't know what type is:
http://www.cplusplus.com/doc/tutorial/variables/

What you need to do is one of the most important parts of your program - saying what values these variables can and can't take.

For example let's look at my quip about how my name is not of type double.

I assume you read that tutorial, but in case it wasn't clear, double is C++ for a double floating point variable. Which means it can be a decimal number for example 3.456.

So you declared the variable "name" to need to be a double floating point variable, meaning it can only be a decimal number like 3.434. Unfortunately, you then wanted the client to input their name into a variable that can only hold decimal digits.

Your user inputs his name in letters. This throws what is called an exception and terminates your program.

In order to prevent such a thing from happening, you need to declare something to hold names which are of type char *

Therefore you could either take the C route (which I don't advise yet) or the C++ string route.

Since you now have included <string> you can create string objects.

They are super easy to do.

string mystring = "This is a string"; // mystring is the name of your string.

So in the case of your program you have the following variables:
tickets,
credits,
cost,
name,
response;
Each of these needs a type based on what data you want to store in it. But I'll leave you to take it from here.

I highly recommend using the tutorial on this website to guide you as you learn C++.

Good luck, Have Fun with C++,
Sean




Topic archived. No new replies allowed.