Error when user inputs nothing

Hey everybody! I'm currently taking my first class in C++ and am very new to programming so my code looks terrible but it's supposed to work!
So, right now I can compile and debug without problems but when the user inputs nothing on my input page the output page crashes the program. My professor saw my "default global initialization" or something and said he didn't like it there and wanted me to put it in my main() module...but it creates 'undeclared identifier' errors. Please help I really don't understand how i can fix 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>

using namespace std;

void title_page(void);
void input();
void output(string, string, string, string, string, string, string);
void main_menu();
void page_cont (void);
string get_str (void);
string isbn("XXX-X-XX-XXXXXX-X"), title("XXXXXXXXXX"), author("XXXXXXXXXX"), required_yn("XXX"), condition("XXXX"), price("XXXXX"), enrollment("XXXXX");

void main (void)
{
	title_page();
	main_menu();
}//end of main()

void title_page(void)//Start title_page:Splash Page
{
//Blah blah pretty page
}//End of title_page()

void page_cont (void)
{
	string press_continue("< P R E S S   E N T E R >");
	string buffer(" ");
	cout << setw(((80-press_continue.length())/2) + press_continue.length()) << press_continue;
	getline(cin, buffer);
}


string get_str(void)
{
	string str;
	getline(cin, str);
	return str;
}//End of get_str

void output(string isbn, string title, string author, string required_yn, string condition, string price, string enrollment)//Start output()/Calculation Page
{
	system ("cls");
	string buffer(" ");

	
	cout << "ISBN(#) : " << isbn << endl << endl;
	cout << "Title : " << title << endl << endl;
	cout << "Author : " << author << endl << endl;
	cout << "Price : $" << price << endl << endl;
	cout << "Enrollment(Expected) : " << enrollment << endl << endl;
	cout << "Condition(New/Used) : " << condition << endl << endl;
	cout << "Required(Yes/No) : " << required_yn << endl;
	cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
		
	//Calculation Block
		double books_to_order = 0.0, final_price = 0.0;

		if ((condition.at(0)=='N')||(condition.at(0)=='n'))
		{
			if ((required_yn.at(0)=='Y')||(required_yn.at(0)=='y'))
				books_to_order = (atoi(enrollment.data()) * 0.32);
			else
				books_to_order = (atoi(enrollment.data()) * 0.17);
		}
		else
		{
			if ((required_yn.at(0)=='Y')||(required_yn.at(0)=='y'))
				books_to_order = atoi(enrollment.data()) * 0.24;
			else
				books_to_order = atoi(enrollment.data()) * 0.10;
		}//End Calculation Block

	string end("THANK YOU FOR USING MY PROGRAM! PRESS ENTER TO RETURN TO MENU");
	final_price = atof(price.data()) * books_to_order;

	cout << " B O O K S  T O  O R D E R : " << books_to_order << "    a t :  $" << final_price;
	cout << endl; cout << endl;
	cout << setw(((80-end.length())/2) + end.length()) << end;
	getline(cin, buffer);
}//End of output()


void input()//Start input():Input Page
{
	system ("cls");
	
	
	cout << "Please input all information(Press Enter to proceed to next input)";
	cout << endl << endl;
	cout << "ISBN(#): "; 
	isbn=get_str(); cout << endl;
	cout << "Title: "; 
	title=get_str(); cout << endl;
	cout << "Author: "; 
	author=get_str(); cout << endl;
	cout << "Price: $"; 
	price=get_str(); cout << endl;
	cout << "Enrollment(Expected): "; 
	enrollment=get_str(); cout << endl;
	cout << "Condition(New/Used): "; 
	condition=get_str(); cout << endl;
	cout << "Required(Yes/No): "; 
	required_yn=get_str(); cout << endl;

	page_cont ();
}//End of input()

	
void main_menu(void)//Start main_menu():User Input	
{
	system("cls");

	string option1=" <1> --->  Data Input Page";
	string option2=" <2> --->  Data Output Page";
	string option3=" <3> --->  Quit";

	string buffer(" ");
	string optionX="ERROR::Wrong Input...";

	char selection;
	string exit = "This program will now exit -- Thank you! ";

	do
	{
		

		cout<<"---- M-A-I-N ---- M-E-N-U ----"<<endl<<endl<<endl;
		cout<<" "<<option1<<endl<<endl;
		cout<<" "<<option2<<endl<<endl;
		cout<<" "<<option3<<endl<<endl<<endl;
		cout<<" "<<"Please Enter a Page Number: ";
		selection = cin.get(); cin.get();

		switch(selection)
		{
			case '1':
				input();
				system ("cls");
				break;
			case '2':
				output(isbn, title, author, required_yn, condition, price, enrollment);
				system ("cls");
				break;
			case '3':
				system ("cls");
				cout << endl<< endl<< endl<< endl<< endl<< endl<< endl<< endl<< endl<< endl<< endl;
				cout << setw(((80-exit.length())/2) + exit.length()) << exit;
				getline(cin, buffer);
				break;
			default:
				cout<< endl<< endl<< endl<< endl;
				cout<<setw(((80-optionX.length())/2)+optionX.length())<<optionX<<endl;
				cout << endl;
				page_cont ();
				system ("cls");
		}//End of switch()
	}while(selection!='3');
}//End of main_menu() 
Topic archived. No new replies allowed.