» Site Navigation | | | » Advertisement | | | » Recent Threads | Beanita. Today 12:29 AM Today 10:35 AM 4 Replies, 5 Views | | | | | I Can't Find 06-14-2008 07:23 PM Today 10:26 AM 8 Replies, 89 Views | | | |  |  | Fuck C++ (Help) |  |
04-29-2008, 12:48 PM
|
#1 (permalink)
| | Resident Psychopath.
Fewmitz is online now Join Date: Nov 2006 Location: fewmitz@live.com Posts: 4,713 Rep Power: 15 | Fuck C++ (Help) So I'm trying to learn C++, again, and I figured I'd make a calculator. But, I"ve got some stupid shit that's getting in the way of it working. Bitch be trippin'.
Anyway, here's the code: Code: #pragma once
/
namespace CalculatorC {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
double result;
double twoRes;
/// <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:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::Button^ button6;
private: System::Windows::Forms::Button^ button7;
private: System::Windows::Forms::Button^ button8;
private: System::Windows::Forms::Button^ button9;
private: System::Windows::Forms::Button^ button10;
private: System::Windows::Forms::Button^ btnE;
private: System::Windows::Forms::TextBox^ txtE;
private: System::Windows::Forms::RadioButton^ rbAdd;
private: System::Windows::Forms::RadioButton^ rbSub;
private: System::Windows::Forms::RadioButton^ rbMult;
private: System::Windows::Forms::RadioButton^ rbDiv;
private: System::Windows::Forms::Button^ button11;
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->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->button6 = (gcnew System::Windows::Forms::Button());
this->button7 = (gcnew System::Windows::Forms::Button());
this->button8 = (gcnew System::Windows::Forms::Button());
this->button9 = (gcnew System::Windows::Forms::Button());
this->button10 = (gcnew System::Windows::Forms::Button());
this->btnE = (gcnew System::Windows::Forms::Button());
this->txtE = (gcnew System::Windows::Forms::TextBox());
this->rbAdd = (gcnew System::Windows::Forms::RadioButton());
this->rbSub = (gcnew System::Windows::Forms::RadioButton());
this->rbMult = (gcnew System::Windows::Forms::RadioButton());
this->rbDiv = (gcnew System::Windows::Forms::RadioButton());
this->button11 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(28, 52);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(25, 20);
this->button1->TabIndex = 0;
this->button1->Text = L"1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(59, 52);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(25, 20);
this->button2->TabIndex = 1;
this->button2->Text = L"2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(90, 52);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(25, 20);
this->button3->TabIndex = 2;
this->button3->Text = L"3";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// button4
//
this->button4->Location = System::Drawing::Point(28, 78);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(25, 20);
this->button4->TabIndex = 3;
this->button4->Text = L"4";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(59, 78);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(25, 20);
this->button5->TabIndex = 4;
this->button5->Text = L"5";
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// button6
//
this->button6->Location = System::Drawing::Point(90, 78);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(25, 20);
this->button6->TabIndex = 5;
this->button6->Text = L"6";
this->button6->UseVisualStyleBackColor = true;
this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
//
// button7
//
this->button7->Location = System::Drawing::Point(28, 104);
this->button7->Name = L"button7";
this->button7->Size = System::Drawing::Size(25, 20);
this->button7->TabIndex = 6;
this->button7->Text = L"7";
this->button7->UseVisualStyleBackColor = true;
this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
//
// button8
//
this->button8->Location = System::Drawing::Point(59, 104);
this->button8->Name = L"button8";
this->button8->Size = System::Drawing::Size(25, 20);
this->button8->TabIndex = 7;
this->button8->Text = L"8";
this->button8->UseVisualStyleBackColor = true;
this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
//
// button9
//
this->button9->Location = System::Drawing::Point(90, 104);
this->button9->Name = L"button9";
this->button9->Size = System::Drawing::Size(25, 20);
this->button9->TabIndex = 8;
this->button9->Text = L"9";
this->button9->UseVisualStyleBackColor = true;
this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
//
// button10
//
this->button10->Location = System::Drawing::Point(28, 130);
this->button10->Name = L"button10";
this->button10->Size = System::Drawing::Size(25, 20);
this->button10->TabIndex = 9;
this->button10->Text = L"0";
this->button10->UseVisualStyleBackColor = true;
this->button10->Click += gcnew System::EventHandler(this, &Form1::button10_Click);
//
// btnE
//
this->btnE->Location = System::Drawing::Point(90, 130);
this->btnE->Name = L"btnE";
this->btnE->Size = System::Drawing::Size(25, 20);
this->btnE->TabIndex = 10;
this->btnE->Text = L"=";
this->btnE->UseVisualStyleBackColor = true;
this->btnE->Click += gcnew System::EventHandler(this, &Form1::btnE_Click);
//
// txtE
//
this->txtE->Enabled = false;
this->txtE->Location = System::Drawing::Point(28, 26);
this->txtE->Name = L"txtE";
this->txtE->Size = System::Drawing::Size(121, 20);
this->txtE->TabIndex = 11;
//
// rbAdd
//
this->rbAdd->AutoSize = true;
this->rbAdd->Location = System::Drawing::Point(121, 54);
this->rbAdd->Name = L"rbAdd";
this->rbAdd->Size = System::Drawing::Size(31, 17);
this->rbAdd->TabIndex = 12;
this->rbAdd->TabStop = true;
this->rbAdd->Text = L"+";
this->rbAdd->UseVisualStyleBackColor = true;
this->rbAdd->CheckedChanged += gcnew System::EventHandler(this, &Form1::rbAdd_CheckedChanged);
//
// rbSub
//
this->rbSub->AutoSize = true;
this->rbSub->Location = System::Drawing::Point(121, 77);
this->rbSub->Name = L"rbSub";
this->rbSub->Size = System::Drawing::Size(28, 17);
this->rbSub->TabIndex = 13;
this->rbSub->TabStop = true;
this->rbSub->Text = L"-";
this->rbSub->UseVisualStyleBackColor = true;
this->rbSub->CheckedChanged += gcnew System::EventHandler(this, &Form1::rbSub_CheckedChanged);
//
// rbMult
//
this->rbMult->AutoSize = true;
this->rbMult->Location = System::Drawing::Point(121, 104);
this->rbMult->Name = L"rbMult";
this->rbMult->Size = System::Drawing::Size(29, 17);
this->rbMult->TabIndex = 14;
this->rbMult->TabStop = true;
this->rbMult->Text = L"*";
this->rbMult->UseVisualStyleBackColor = true;
this->rbMult->CheckedChanged += gcnew System::EventHandler(this, &Form1::rbMult_CheckedChanged);
//
// rbDiv
//
this->rbDiv->AutoSize = true;
this->rbDiv->Location = System::Drawing::Point(121, 127);
this->rbDiv->Name = L"rbDiv";
this->rbDiv->Size = System::Drawing::Size(30, 17);
this->rbDiv->TabIndex = 15;
this->rbDiv->TabStop = true;
this->rbDiv->Text = L"/";
this->rbDiv->UseVisualStyleBackColor = true;
this->rbDiv->CheckedChanged += gcnew System::EventHandler(this, &Form1::rbDiv_CheckedChanged);
//
// button11
//
this->button11->Location = System::Drawing::Point(59, 130);
this->button11->Name = L"button11";
this->button11->Size = System::Drawing::Size(25, 20);
this->button11->TabIndex = 16;
this->button11->Text = L".";
this->button11->UseVisualStyleBackColor = true;
this->button11->Click += gcnew System::EventHandler(this, &Form1::button11_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->button11);
this->Controls->Add(this->rbDiv);
this->Controls->Add(this->rbMult);
this->Controls->Add(this->rbSub);
this->Controls->Add(this->rbAdd);
this->Controls->Add(this->txtE);
this->Controls->Add(this->btnE);
this->Controls->Add(this->button10);
this->Controls->Add(this->button9);
this->Controls->Add(this->button8);
this->Controls->Add(this->button7);
this->Controls->Add(this->button6);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = "1";
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "2";
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "3";
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "4";
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "5";
}
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "6";
}
private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "7";
}
private: System::Void button8_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "8";
}
private: System::Void button9_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "9";
}
private: System::Void button10_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + "0";
}
private: System::Void button11_Click(System::Object^ sender, System::EventArgs^ e) {
txtE->Text = txtE->Text + ".";
}
private: System::Void rbAdd_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
result = Double::Parse(txtE->Text);
txtE->Text = "";
}
private: System::Void rbSub_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
result = Double::Parse(txtE->Text);
txtE->Text = "";
}
private: System::Void rbMult_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
result = Double::Parse(txtE->Text);
txtE->Text = "";
}
private: System::Void rbDiv_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
result = Double::Parse(txtE->Text);
txtE->Text = "";
}
private: System::Void btnE_Click(System::Object^ sender, System::EventArgs^ e) {
if(rbAdd->Checked){
result = result + Double::Parse(txtE->Text);
txtE->Text = result.ToString();
rbAdd->Checked = false;
}
if(rbSub->Checked){
result = result - Double::Parse(txtE->Text);
txtE->Text = result.ToString();
rbSub->Checked = false;
}
if(rbMult->Checked){
result = result * Double::Parse(txtE->Text);
txtE->Text = result.ToString();
rbMult->Checked = false;
}
if(rbDiv->Checked){
result = result / Double::Parse(txtE->Text);
// txtE->Text = result;
rbDiv->Checked = false;
}
};
}
/////////////////////////////////////////Here's the .cpp:
// CalculatorC.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace CalculatorC;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
//////////////////////////And here's the build output
1>------ Build started: Project: CalculatorC, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>CalculatorC.cpp
1>.\CalculatorC.cpp(6) : error C2143: syntax error : missing ';' before 'using'
1>i:\calculatorc\calculatorc\Form1.h(28) : error C2059: syntax error : 'inline function header'
1>i:\calculatorc\calculatorc\Form1.h(28) : error C2143: syntax error : missing ';' before '{'
1>i:\calculatorc\calculatorc\Form1.h(28) : error C2447: '{' : missing function header (old-style formal list?)
1>.\CalculatorC.cpp(6) : error C2059: syntax error : ';'
1>.\CalculatorC.cpp(19) : fatal error C1075: end of file found before the left brace '{' at 'i:\calculatorc\calculatorc\Form1.h(4)' was matched
1>Build log was saved at "file://i:\CalculatorC\CalculatorC\Debug\BuildLog.htm"
1>CalculatorC - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== The problem is I haven't touched .cpp file, so I have no idea what's going on here. The rest of the errors popped up as soon as I brought the project home, but the main thing I'm trying to fix here is the errors centered around the .cpp
RRRR
__________________ | |
| |  |  | |  |
04-30-2008, 12:45 PM
|
#2 (permalink)
| | Resident Psychopath.
Fewmitz is online now Join Date: Nov 2006 Location: fewmitz@live.com Posts: 4,713 Rep Power: 15 | Yeah, I figured it out.
For those who are interested, the bottom of the header should have looked like this: Code: private: System::Void btnE_Click(System::Object^ sender, System::EventArgs^ e) {
if(rbAdd->Checked){
result = result + Double::Parse(txtE->Text);
txtE->Text = result.ToString();
rbAdd->Checked = false;
}
if(rbSub->Checked){
result = result - Double::Parse(txtE->Text);
txtE->Text = result.ToString();
rbSub->Checked = false;
}
if(rbMult->Checked){
result = result * Double::Parse(txtE->Text);
txtE->Text = result.ToString();
rbMult->Checked = false;
}
if(rbDiv->Checked){
result = result / Double::Parse(txtE->Text);
// txtE->Text = result;
rbDiv->Checked = false;
}
}
}; And then the .cpp should have looked like this: Code: // CalculatorC.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace CalculatorC;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
}; Brackets.
__________________ | |
| |  |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |