CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2013
    Posts
    2

    Unhappy Problem regarding the coding error !

    i , i'm using the Borland C++ builder for programming and i've been trying to resolve this issue as whenever i try to run it, it gives me an error OR am i missing something ?

    This code is supposed to do is if you press on “Accept” button, the entered number will be sent to the array named A1 and it should validate the number and the Accept button will be disabled after you accept five numbers.
    If you press on “Exc” button, the lower number in the array A1 will be found and it will be displayed in the memo.

    And it has one one editbox named Edit1 that holds the input number and one memo named Memo1 and two buttons named Accept and Exc. And i already have declared array of 5 integers initialized by zeros.


    Code:
    int num;
    int A1[5]= {0, 0, 0, 0, 0 };
    int i;
    int j;
    int count;
    
    
    void __fastcall TForm1::AcceptClick(TObject *Sender)
    {
               num=Edit1->Text.ToInt();   
           A1[i] = num;  
           count++; 
    
    
    if (count==5)  
            Accept->Enabled=false;   
    
    
    
    
    }
    //---------------------------------------------------------------------------
    
    
    void __fastcall TForm1::ExcClick(TObject *Sender)
    
    
    {
    min=A1[0] 
                for(int j=1; j<5; j++)  
                {
                       if(A1[j] < min)   
                min= A1[j]; 
                }
        Memo1->Lines->Add(AnsiString(num));  
    
    
    }
    Your quick reply would be highly appreciated !

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Problem regarding the coding error !

    You could start by checking that all variables are assigned a valid value.
    Nobody cares how it works as long as it works

  3. #3
    Join Date
    Dec 2013
    Posts
    2

    Re: Problem regarding the coding error !

    I've checked several times but still not working...pls help

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Problem regarding the coding error !

    Code:
    A1[i] = num;  
    count++;
    Where are i and count initialised?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Problem regarding the coding error !

    Quote Originally Posted by naughtyaashiq View Post
    i , i'm using the Borland C++ builder for programming
    This forum are for questions concerning the Visual C++ compiler, not Borland.
    and i've been trying to resolve this issue as whenever i try to run it, it gives me an error OR am i missing something ?
    How about debugging the program? I'm sure Borland C++ comes with a debugger.

    Also, please clarify "gives me an error". You're already in the wrong forum, so you need to do us a favor, pretend that Borland doesn't exist, and tell us what the issue is. Is it the copying of data from one array to another?

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Problem regarding the coding error !

    Quote Originally Posted by 2kaud View Post
    Code:
    A1[i] = num;  
    count++;
    Where are i and count initialised?
    Well if they're global, then they're are initialized to 0. But that brings up the point of having global variables named "i". That is the absolute worst name to give a global variable.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured