Like Tree1Likes
  • 1 Post By Salem

Code Help: Right Triangle Solver

This is a discussion on Code Help: Right Triangle Solver within the Windows Programming forums, part of the Platform Specific Boards category; Can someone help me find what I did wrong? Code: #pragma once namespace RightTriangleSolver { using namespace System; using namespace ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    Code Help: Right Triangle Solver

    Can someone help me find what I did wrong?

    Code:
    #pragma once
    
    
    namespace RightTriangleSolver {
    
    
        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
        /// </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;
                }
            }
    
    
        protected: 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        private: System::Windows::Forms::Label^ label4;
        private: System::Windows::Forms::Label^ label1;
        private: System::Windows::Forms::Label^ label2;
        private: System::Windows::Forms::Label^ label3;
    
    
    
    
        private: System::Windows::Forms::Button^ button3;
        private: System::Windows::Forms::TextBox^ num1;
        private: System::Windows::Forms::TextBox^ num2;
        private: System::Windows::Forms::TextBox^ c;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        private: System::ComponentModel::IContainer^ components;
    
    
        protected: 
    
    
        private:
            /// <summary>
            /// Required designer variable.
            /// </summary>
    
    
    
    
    #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->label4 = (gcnew System::Windows::Forms::Label());
                this->label1 = (gcnew System::Windows::Forms::Label());
                this->label2 = (gcnew System::Windows::Forms::Label());
                this->label3 = (gcnew System::Windows::Forms::Label());
                this->button3 = (gcnew System::Windows::Forms::Button());
                this->num1 = (gcnew System::Windows::Forms::TextBox());
                this->num2 = (gcnew System::Windows::Forms::TextBox());
                this->c = (gcnew System::Windows::Forms::TextBox());
                this->SuspendLayout();
                // 
                // label4
                // 
                this->label4->AutoSize = true;
                this->label4->Font = (gcnew System::Drawing::Font(L"Segoe Print", 26.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                    static_cast<System::Byte>(0)));
                this->label4->ForeColor = System::Drawing::Color::Red;
                this->label4->Location = System::Drawing::Point(44, 9);
                this->label4->Name = L"label4";
                this->label4->Size = System::Drawing::Size(400, 61);
                this->label4->TabIndex = 8;
                this->label4->Text = L"Right Triangle Solver";
                // 
                // label1
                // 
                this->label1->AutoSize = true;
                this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                    static_cast<System::Byte>(0)));
                this->label1->Location = System::Drawing::Point(51, 109);
                this->label1->Name = L"label1";
                this->label1->Size = System::Drawing::Size(32, 31);
                this->label1->TabIndex = 9;
                this->label1->Text = L"A";
                // 
                // label2
                // 
                this->label2->AutoSize = true;
                this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                    static_cast<System::Byte>(0)));
                this->label2->Location = System::Drawing::Point(51, 164);
                this->label2->Name = L"label2";
                this->label2->Size = System::Drawing::Size(32, 31);
                this->label2->TabIndex = 10;
                this->label2->Text = L"B";
                // 
                // label3
                // 
                this->label3->AutoSize = true;
                this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                    static_cast<System::Byte>(0)));
                this->label3->Location = System::Drawing::Point(49, 221);
                this->label3->Name = L"label3";
                this->label3->Size = System::Drawing::Size(34, 31);
                this->label3->TabIndex = 11;
                this->label3->Text = L"C";
                // 
                // button3
                // 
                this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                    static_cast<System::Byte>(0)));
                this->button3->Location = System::Drawing::Point(193, 265);
                this->button3->Name = L"button3";
                this->button3->Size = System::Drawing::Size(113, 30);
                this->button3->TabIndex = 14;
                this->button3->Text = L"Solve for C!";
                this->button3->UseVisualStyleBackColor = true;
                this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
                // 
                // num1
                // 
                this->num1->Location = System::Drawing::Point(165, 106);
                this->num1->Name = L"num1";
                this->num1->Size = System::Drawing::Size(169, 20);
                this->num1->TabIndex = 15;
                // 
                // num2
                // 
                this->num2->Location = System::Drawing::Point(165, 163);
                this->num2->Name = L"num2";
                this->num2->Size = System::Drawing::Size(169, 20);
                this->num2->TabIndex = 16;
                // 
                // c
                // 
                this->c->Location = System::Drawing::Point(165, 221);
                this->c->Name = L"c";
                this->c->Size = System::Drawing::Size(169, 20);
                this->c->TabIndex = 17;
                // 
                // Form1
                // 
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(471, 307);
                this->Controls->Add(this->c);
                this->Controls->Add(this->num2);
                this->Controls->Add(this->num1);
                this->Controls->Add(this->button3);
                this->Controls->Add(this->label3);
                this->Controls->Add(this->label2);
                this->Controls->Add(this->label1);
                this->Controls->Add(this->label4);
                this->Name = L"Form1";
                this->Text = L"Form1";
                this->ResumeLayout(false);
                this->PerformLayout();
    
    
            }
    #pragma endregion
        private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
                 }
        private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
                 }
    private: System::Void pictureBox1_Click_1(System::Object^ sender, System::EventArgs^ e) {
             }
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
             }
    private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
                 this->c = Math::Sqrt(Math::Pow(num1,2)+Math::Pow(num2,2));
             }
    };
    }
    ERROR:1>------ Build started: Project: Right Triangle Solver, Configuration: Debug Win32 ------
    1>Build started 1/22/2013 1:31:45 PM.
    1>InitializeBuildStatus:
    1> Touching "Debug\Right Triangle Solver.unsuccessfulbuild".
    1>GenerateTargetFrameworkMonikerAttribute:
    1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
    1>ClCompile:
    1> All outputs are up-to-date.
    1> Right Triangle Solver.cpp
    1>c:\users\admin\documents\visual studio 2010\projects\right triangle solver\right triangle solver\Form1.h(215): error C2664: 'System::Math::Pow' : cannot convert parameter 1 from 'System::Windows::Forms::TextBox ^' to 'double'
    1> No user-defined-conversion operator available, or
    1> There is no context in which this conversion is possible
    1>c:\users\admin\documents\visual studio 2010\projects\right triangle solver\right triangle solver\Form1.h(215): error C2664: 'System::Math::Pow' : cannot convert parameter 1 from 'System::Windows::Forms::TextBox ^' to 'double'
    1> No user-defined-conversion operator available, or
    1> There is no context in which this conversion is possible
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:00.77
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Are you learning C++, or Microsoft's messed up managed C++ ?
    Elysia likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Its supposed to be Microsoft C++ (I guess?)
    I'm using Microsoft Visual Studio 2010 to create an "Windows Forms Application" Its supposed to solve for the Hypotenuse on a right triangle, After filling in the two text boxes (a and b) then pressing the button (button1) and put the answer in the final text box (c). But I always seem to end up with a build failed error.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,294
    num1 and num2 are text boxes. you need to extract the text from the text boxes and convert to a double before you can compute any kind of result.

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Quote Originally Posted by Elkvis View Post
    num1 and num2 are text boxes. you need to extract the text from the text boxes and convert to a double before you can compute any kind of result.
    How do i do that? Sorry I'm really new at this...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code for pascal triangle
    By suryak in forum C Programming
    Replies: 7
    Last Post: 05-20-2011, 08:34 AM
  2. maze solver
    By iamnew in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2010, 02:46 AM
  3. Help for a sudoku Solver
    By axilleask in forum C Programming
    Replies: 3
    Last Post: 11-26-2007, 03:28 PM
  4. Resizing a triangle. Why is my code not working?
    By gozu in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2007, 05:40 PM
  5. algebra solver
    By treenef in forum C++ Programming
    Replies: 20
    Last Post: 03-18-2005, 11:12 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21