View Poll Results: has anyone ever been far as really decided to use want to do look more like?
- Voters
- 1. You may not vote on this poll
-
Jul 29th, 2010, 02:48 PM
#1
Thread Starter
Addicted Member
how do i???
find the smallest valuse in an array?
i have the way to find the biggest value... but i cant see how i can use it to get the smallest value...
Code:
//find biggest number
long int big = numbers[i];
while(x<=i)
{
if(big<numbers[x])
{
if (numbers[x]==-99){break;}
else
{
big = numbers[x];
}
}
else
{
x++;
}
}
cout << "Biggest Number : " << big <<endl;
Code:
//find the smallest number
long int smalll = numbers[i];
while(y<=i)
{
if(smalll>numbers[y])
{
if (numbers[y]==-99){break;}
else
{
smalll = numbers[y];
}
}
else
{
y++;
}
}
cout << "Smallest Number : " << smalll <<endl;
heres all of my code
Code:
#include <iostream>
#include<iomanip>
using namespace std;
// vars
long int dano=0, i=0, ii=0, w=0, x=0, y=0, z=0, maxx=10;
long int *numbers = new long int[maxx];
bool thegame = false;
// vars
int main ()
{
while(i!=-1)
{
if (i >= maxx)
{
maxx = maxx * 2; // double the previous size
long int* temp = new long int[maxx]; // create new bigger array.
for (int z=0; z<i; z++) {
temp[z] = numbers[z]; // copy values to new array.
}
delete [] numbers; // free old array memory.
numbers = temp; // now a points to new array.
}
cout<<"number " << i+1 << ": ";
cin>>numbers[i];
i++;
//loop to go thru and see if -99 was entered
while (w!=i)
{
if (numbers[w]==-99){thegame=true; break;}
else w++;
}
if (thegame == true){break;}
}
//outputs all the entered values
while(ii<=i)
{
if (!(numbers[ii]==-99))
{
cout << numbers[ii]<<endl;
ii++;
}
else
{
break;
}
}
///find the largest number
long int big = numbers[i];
while(x<=i)
{
if(big<numbers[x])
{
if (numbers[x]==-99){break;}
else
{
big = numbers[x];
}
}
else
{
x++;
}
}
cout << "Biggest Number : " << big <<endl;
//find the smallest number
long int smalll = numbers[i];
while(y<=i)
{
if(smalll>numbers[y])
{
if (numbers[y]==-99){break;}
else
{
smalll = numbers[y];
}
}
else
{
y++;
}
}
cout << "Smallest Number : " << smalll <<endl;
}
-
Jul 31st, 2010, 10:22 AM
#2
Re: how do i???
Try this:
Code:
y=0
long int smalll = numbers[y]; //first element will be stored
while(y<=i)
{
if(smalll>numbers[y])
{
if (numbers[y]==-99){break;}
else
{
smalll = numbers[y];
}
}
else
{
y++;
}
}
cout << "Smallest Number : " << smalll <<endl;
I'm not sure, because I didn't tested it and never used VC++ before 
.....
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
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
|