-
December 9th, 2013, 09:22 PM
#1
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 !
-
December 10th, 2013, 04:05 AM
#2
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
-
December 10th, 2013, 08:59 AM
#3
Re: Problem regarding the coding error !
I've checked several times but still not working...pls help
-
December 10th, 2013, 09:02 AM
#4
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)
-
December 10th, 2013, 07:32 PM
#5
Re: Problem regarding the coding error !
Originally Posted by naughtyaashiq
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
-
December 10th, 2013, 07:34 PM
#6
Re: Problem regarding the coding error !
Originally Posted by 2kaud
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|