Program Errors

Hey all, so I have this code right here but it's returning a fair amount of errors and I was wondering if I could have a couple more eyes to help me correct them.

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
  //This program formats a shipping label with a pseudo barcode for printing and placing on a package.
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

int main()
{
	int input; //To hold user mailing choice input. 
	string name, streetAddress, city, state, zipcode; //To hold user location input information.
	int number, numberOfMailings; //To hold the user number input information.
	const double cost1=0.49, cost2=0.98, cost3=2.54, addCharge1=0.22, addCharge2=0.20; //To hold the given constants.
	const int singleMail=1, multiMail=2, quitMail=3;
	double weight, postage, totalPostage; //To hold user input data.
	
	//Gather user input data.
	do
	{
		//Display Menu
		cout<<"Mailing Options Menu:\n\n";
		cout<<"1. Single Item Mailing\n";
		cout<<"2. Multiple Item Mailing\n";
		cout<<"3. Quit Program\n";
		cin>>input;
		
		//Validate the user's input.
		while (input<singleMail||input>quitMail)
		{
			cout<<"Invalid input, please enter a valid input:";
			cin>>input;
		}
		
		//Response to user's input.
		switch (input)
		{
			case singleMail:
				cout<<"Please enter your name:";
				getline(cin, name);
				cout<<"Please enter your street address:";
				getline(cin, streetAddress);
				cout<<"Please enter your city:";
				getline(cin, city);
				cout<<"Please enter your state:";
				getline(cin, state);
				cout<<"Please enter your zipcode:";
				cin>>zipcode;
				cout<<"Please enter 1 for letter, 2 for envelope or 3 for parcel:";
				cin>>number;
				cout<<"Please enter item's weight in ounces:";
				cin>>weight;
				
				//Calculate the cost of the item based off of type and weight.
				if (number==1&&weight<=1)
					cout<<"******************************"<<cost1<<"\n\n";
				else if (number==1&&weight>1)
					cout<<"******************************"<<cost1+(weight*addCharge1)<<"\n\n";
				else if (number==2&&weight<=1)
					cout<<"******************************"<<cost2<<"\n\n";	
				else if (number==2&&weight>1)
					cout<<"******************************"<<cost2+(weight*addCharge1)<<"\n\n";
				else if (number==3&&weight<=3)	
					cout<<"******************************"<<cost3<<"\n\n";
				else if (number==3&&weight>3)
					cout<<"******************************"<<cost3+(weight*addCharge2)<<"\n\n";
				else 
					cout<<"Invalid input, restart program."<<endl;
					
				//The following will output the address information based off the user input.
				cout<<name<<endl;
				cout<<streetAddress<<endl;
				cout<<city<<", "<<state<<" "<<zipcode<<"\n\n";
				
				//The following converts the user input zipcode into a barcode.
				string result;
				char digit;
				int checkSum;
				{
   				if (digit == '0')
        			result= "||:::";
   				else if (digit == '1')
       				result= ":::||";
   				else if (digit == '2')
       				result= "::|:|";
   				else if (digit == '3')
     	    		result= "::||:";
  				else if (digit == '4')
   	    			result= ":|::|";
  				else if (digit == '5')
            		result= ":|:|:";
   				else if (digit == '6')
        			result= ":||::";
    			else if (digit == '7')
        			result= "|:::|";
    			else if (digit == '8')
        			result= "|:::|";
   				else if (digit == '9')
        			result= "|:|::";
    			else
        			result= "Invalid";
        		}
        		
        		checkSum = (std::stoi(zipcode) % 10);
				result = CreateBarCode(zipcode + std::to_string(checkSum));
				
				std::cout << "| " << result << " | " << zipcode << checkSum << " |"; //Displays barcode.
				
				
			case multiMail:
				while (ReadFile(inFile, name, streetAddress, city, state, zipCode, number, weight))
				{
					totalPostage += CalculatePostage(number, weight);

					PrintInfo(name, streetAddress, city, state, zipCode, number, weight);
				}
				
				//The following converts the user input zipcode into a barcode.
				string result;
				char digit;
				int checkSum;
				{
   				if (digit == '0')
        			result= "||:::";
   				else if (digit == '1')
       				result= ":::||";
   				else if (digit == '2')
       				result= "::|:|";
   				else if (digit == '3')
     	    		result= "::||:";
  				else if (digit == '4')
   	    			result= ":|::|";
  				else if (digit == '5')
            		result= ":|:|:";
   				else if (digit == '6')
        			result= ":||::";
    			else if (digit == '7')
        			result= "|:::|";
    			else if (digit == '8')
        			result= "|:::|";
   				else if (digit == '9')
        			result= "|:|::";
    			else
        			result= "Invalid";
        		}
			
				checkSum = (std::stoi(zipcode) % 10);
				result = CreateBarCode(zipcode + std::to_string(checkSum));

				std::cout << "| " << result << " | " << zipode << checkSum << " |"; //Displays barcode.
			
			
				std::cout << "\n\n Total postage is $" << std::setw(5) << totalPostage << std::endl;

				break;
				
			case quitMail:
				cont = false;
				break;
			return 0;
		}
	}
		
}


These are the errors I'm getting:

C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp In function 'int main()':
102 23 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'stoi' is not a member of 'std'
103 38 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'to_string' is not a member of 'std'
103 62 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'CreateBarCode' was not declared in this scope
109 10 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] jump to case label [-fpermissive]
74 12 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] crosses initialization of 'std::string result'
110 21 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'inFile' was not declared in this scope
110 63 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'zipCode' was not declared in this scope
110 86 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'ReadFile' was not declared in this scope
112 53 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'CalculatePostage' was not declared in this scope
114 73 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'PrintInfo' was not declared in this scope
118 12 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] redeclaration of 'std::string result'
74 12 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Note] 'std::string result' previously declared here
119 10 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] redeclaration of 'char digit'
75 10 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Note] 'char digit' previously declared here
120 9 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] redeclaration of 'int checkSum'
76 9 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Note] 'int checkSum' previously declared here
146 17 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'stoi' is not a member of 'std'
147 38 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'to_string' is not a member of 'std'
149 45 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'zipode' was not declared in this scope
152 47 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'setw' is not a member of 'std'
156 9 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] jump to case label [-fpermissive]
74 12 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] crosses initialization of 'std::string result'
157 5 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] 'cont' was not declared in this scope
165 1 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] expected 'while' before '}' token
165 1 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] expected '(' before '}' token
165 1 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] expected primary-expression before '}' token
165 1 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] expected ')' before '}' token
165 1 C:\Users\Christopher Mangum\Documents\School\C++\project3_chris_mangum.cpp [Error] expected ';' before '}' token


Thanks in advance. I'm working on them now so I'm sure I'll have quite a few gone one my own by the time I get responses.
Always start with the first error, and look at the line number; the actual error will usually be close to the line number that it says something wrong is happening on (usually!).

Your first problem is that you're declaring std::string result in more than one place - see line 74 and 117. Only declare it once.
Same thing with digit and checksum.
You also can't declare the variables there because they are within the same switch block.
See: https://stackoverflow.com/questions/11578936/getting-a-bunch-of-crosses-initialization-error

1
2
102	[Error] 'stoi' is not a member of 'std'
103	[Error] 'to_string' is not a member of 'std'


Are you compiling with C++11? Add -std=c++11 or if that doesn't work, -std=c++0x to your compiler options if you're working with GCC (g++). Some older version of MinGW have a bug where those string conversion functions don't work, so you have to make your own.

You also never define a function called CreateBarCode.

#include <iomanip> is needed for std::setw

cont, zipode --> both typos.

A "do" loop is actually a do-while loop. The require syntax looks like this:
1
2
3
4
5
bool my_condition = true
do
{
    std::cout << "Do stuff, modify condition to false to end the loop" << std::endl;
} while (condition);


PRO-TIP: COMPILE INCREMENTALLY. Don't write your own program in one go and then try to compile. Make sure it can compile, and then add more onto it. Otherwise, you end up with 100 errors like this.
Last edited on
Topic archived. No new replies allowed.