Changing number to string in guessing game

I've only been programming in C++ for a few weeks. Now, I have a project that the teacher has given little information about for Visual Studio 2008 in Windows Forms. We have to make a window for a number guessing game, the user can enter a number from 0-100, press a button to evaluate it, if too high show the label 'too high', if too low show the label 'too low' and increase the number count of tries. My problem is changing the input to an int or changing the random number to a string. After this I can compare the input with the random number, but when I try to put in a string I get errors, all dealing with the string:

1>c:\smith\lab6b\lab6b\Form1.h(29) : error C2146: syntax error : missing ';' before identifier 'numberToString'
1>c:\smith\lab6b\lab6b\Form1.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\smith\lab6b\lab6b\Form1.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int


Here is my code:

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

#pragma once
#include <ctime>
#include <cstdlib>
#include <string>

namespace Lab6B {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		int randomNumber;
		string numberToString;
				
		Form1(void)
		{
			InitializeComponent();
			
			randomNumber = 0;
			
			
			
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			
			srand(time(0));
			randomNumber = rand() % 100;
			itoa (randomNumber,numberToChar,10);
			

			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  lblUserInform;
	private: System::Windows::Forms::Button^  btnEvaluate;
	private: System::Windows::Forms::Button^  btnTryAgain;
	protected: 

	protected: 


	private: System::Windows::Forms::Label^  lblTooLow;
	private: System::Windows::Forms::Label^  lblTooHigh;


	private: System::Windows::Forms::TextBox^  txtUserInput;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->lblUserInform = (gcnew System::Windows::Forms::Label());
			this->btnEvaluate = (gcnew System::Windows::Forms::Button());
			this->btnTryAgain = (gcnew System::Windows::Forms::Button());
			this->lblTooLow = (gcnew System::Windows::Forms::Label());
			this->lblTooHigh = (gcnew System::Windows::Forms::Label());
			this->txtUserInput = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// lblUserInform
			// 
			this->lblUserInform->AutoSize = true;
			this->lblUserInform->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->lblUserInform->Location = System::Drawing::Point(50, 79);
			this->lblUserInform->Name = L"lblUserInform";
			this->lblUserInform->Size = System::Drawing::Size(126, 15);
			this->lblUserInform->TabIndex = 0;
			this->lblUserInform->Text = L"Enter a guess 1 - 100:";
			// 
			// btnEvaluate
			// 
			this->btnEvaluate->Location = System::Drawing::Point(69, 197);
			this->btnEvaluate->Name = L"btnEvaluate";
			this->btnEvaluate->Size = System::Drawing::Size(187, 47);
			this->btnEvaluate->TabIndex = 1;
			this->btnEvaluate->Text = L"Press to EVALUATE your guess!";
			this->btnEvaluate->UseVisualStyleBackColor = true;
			this->btnEvaluate->Click += gcnew System::EventHandler(this, &Form1::btnEvaluate_Click);
			// 
			// btnTryAgain
			// 
			this->btnTryAgain->Location = System::Drawing::Point(69, 286);
			this->btnTryAgain->Name = L"btnTryAgain";
			this->btnTryAgain->Size = System::Drawing::Size(187, 66);
			this->btnTryAgain->TabIndex = 2;
			this->btnTryAgain->Text = L"Press to CLEAR your guess and TRY AGAIN!";
			this->btnTryAgain->UseVisualStyleBackColor = true;
			this->btnTryAgain->Visible = false;
			this->btnTryAgain->Click += gcnew System::EventHandler(this, &Form1::btnTryAgain_Click);
			// 
			// lblTooLow
			// 
			this->lblTooLow->AutoSize = true;
			this->lblTooLow->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->lblTooLow->Location = System::Drawing::Point(66, 125);
			this->lblTooLow->Name = L"lblTooLow";
			this->lblTooLow->Size = System::Drawing::Size(60, 15);
			this->lblTooLow->TabIndex = 3;
			this->lblTooLow->Text = L"Too Low!!";
			this->lblTooLow->Visible = false;
			// 
			// lblTooHigh
			// 
			this->lblTooHigh->AutoSize = true;
			this->lblTooHigh->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->lblTooHigh->Location = System::Drawing::Point(212, 125);
			this->lblTooHigh->Name = L"lblTooHigh";
			this->lblTooHigh->Size = System::Drawing::Size(63, 15);
			this->lblTooHigh->TabIndex = 4;
			this->lblTooHigh->Text = L"Too High!!";
			this->lblTooHigh->Visible = false;
			// 
			// txtUserInput
			// 
			this->txtUserInput->Location = System::Drawing::Point(208, 74);
			this->txtUserInput->MaxLength = 3;
			this->txtUserInput->Name = L"txtUserInput";
			this->txtUserInput->Size = System::Drawing::Size(100, 20);
			this->txtUserInput->TabIndex = 5;
			this->txtUserInput->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::SystemColors::ActiveCaption;
			this->ClientSize = System::Drawing::Size(337, 398);
			this->Controls->Add(this->txtUserInput);
			this->Controls->Add(this->lblTooHigh);
			this->Controls->Add(this->lblTooLow);
			this->Controls->Add(this->btnTryAgain);
			this->Controls->Add(this->btnEvaluate);
			this->Controls->Add(this->lblUserInform);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
				 
			 }
private: System::Void btnEvaluate_Click(System::Object^  sender, System::EventArgs^  e) {
			 this->btnTryAgain->Visible = true;
			 this->btnEvaluate->Visible = false;
			 this->btnTryAgain->Focus();
			 this->BackColor = System::Drawing::SystemColors::HotTrack;
			 			 
		 }
private: System::Void btnTryAgain_Click(System::Object^  sender, System::EventArgs^  e) {
			 this->btnEvaluate->Visible = true;
			 this->btnTryAgain->Visible = false;
			 this->txtUserInput->Clear();
			 this->btnEvaluate->Focus();
			 this->BackColor = System::Drawing::SystemColors::ActiveCaption;
			 
		 }
};
}

but but but... this isn't c++!
True, it's not C++, but we could still tell the OP that it's std::string instead of just string at line 29, right?

-Albatross
*shrugging shoulders*

Dunno... guess it's java?

anyway, the compiler error message says "C++" in it.

I think Microsoft is trying to put people under the impression that C++/CLI is C++... maybe this is just my cynicism though.

-Albatross
Well, it doesn't look like Java to me. In Java, "this" is used like this.member There is no need to dereference "this" in Java.
It's CLI/C++ I believe.
This is from Visual Studio Windows Forms. When I try the std::string I still get an error:

error C4368: cannot define 'numberToString' as a member of managed 'Lab6B::Form1': mixed types are not supported


 
std::string numberToString;

Last edited on
In CLI use String instead with a uppercase 'S'.
error C2039: 'String' : is not a member of 'std'
error C3149: 'System::String' : cannot use this type here without a top-level '^'

These are the errors when I capitalize it.
Yes, then it's a CLI variable as shown on line 61 - 73. And itoa() won't work with it either. CLI might look similar to C++ but it isn't.
So how can I get it to work? Like I said, we were coding in C++, and have been for only a few weeks, and now the teacher wants a program made in CLI. I have no idea how to do it, where to start and others in my class are frustrated too. DeVry doesn't even have anyone that is in student help for C++.
Topic archived. No new replies allowed.