totally lost c++ help again -__-"

Locust

I is a ninja =D
Feb 23, 2010
491
0
21
Lahore
NOTE... I dont want the actual answer of the syntax to solve the problem i want the strategy good damn it i like to figure it out on my own so dont spoil it for me :mad: if i cant do it i will ask for the actual answer myself..until then..hint me guys..


after sucessfully completeing the first assignment becuz of the gurus here.. i was doing epic i was doing assignment and lab assignments like a pro..gentlmen i have come to the point where my teacher has stumped me again.. i now need the help..
dont worry i did try this time.. phas gaya hoon..

TASK: take 10 input values from the user and show the maximum and minimum value..
ok here is wat i did...
FIRST THE HIGH NUMBER PART...i will figure the small value after that..

void main()
{
.
BLA BLA BLA YADDA YADDA;
.
for(int i=0;i<=0;i++)
{
cin>>N;
}
.
.
BLAH BLAH BLAH YAADA YADDA YADD
for(int a=0; a<=8; a++)
{
if( N > N[i+1] )
high=N;

BLA BLA BLA

here is my question... assuming the loop goes once cuz of the if statement it will compair N[0] and N[1] then on the next run N[1]>N[2]
wat if N[2] is greater then N[0]????
how do i make it so that all the N[0] to N[9] compair each other.. again no smart pants moves i might not get..

YESH!!! HELP ME NOW..
 
Last edited:

Crow

Seasoned
Jan 22, 2007
3,415
4
44
Don't compare N to N[i+1].

Set a new variable (suppose "max"), and set it to the first value of the array, i.e., max = N[0].

Now, inside the loop...

if(max < N)
max = N;

Done.
 

Locust

I is a ninja =D
Feb 23, 2010
491
0
21
Lahore
Man why did u do that?? I dont want it to be solved i wanted hints i like figuring out on my own... Khair good thing is i didnt get a word u jus said.. Khair.. Gimme a hint.. Do i need 2 if statements for max and min value or would one do it?
 

Locust

I is a ninja =D
Feb 23, 2010
491
0
21
Lahore
Ahan interesting.. By 2 loops u mean one for input and one for checking and solving the greater and smaller integer values??? I already know that..i m asking bout the if statement that would differentiate the greater and smaller value..like for xample.. Do i need 2 if statements for larger and smaller seperatly..or do i have to use 1 only that would sort both out... If i need 2.. Put goes after ...'else'... In both the statements?
 

Ottoman

Senior
Sep 15, 2008
8,587
3
44
Wow Chhowni
Would you be more specific Locust? If i'm getting it right the user is inputting ten integer values. The program then displays only the maximum and minimum values? Or is it in the ascending/descending order?
 

Crow

Seasoned
Jan 22, 2007
3,415
4
44
Man why did u do that?? I dont want it to be solved i wanted hints i like figuring out on my own... Khair good thing is i didnt get a word u jus said.. Khair.. Gimme a hint.. Do i need 2 if statements for max and min value or would one do it?
You need two statements and two variables (you can do both in one loop).

Suppose a series: 2, 22, 77, 3, 43, 17, 23, 74, 88, 19

For maximum value, you will take a variable and compare it with all the elements in the series. As a starting point, we set the variable ("max") as the first element so we can compare it with the rest of the series.

So here, we suppose max = 2.

Now we compare this with all the elements in the series one by one. When it encounters an element that is greater than "max", we set it equal to "max" (because we are finding the maximum value). So in this series, max will be equal to 22, then 77, and then 88. Thus, when the loop ends, max = 88.

Once you understand this, you can find the minimum value easily, which is done similarly.
 

ASKnASK

Crit-Monster™
Dec 23, 2007
11,011
50
54
Wow Cantt
www.facebook.com
:) Basic C++... Gotta love it :p I'm stuck in my final project (OOP) these days -.- But that's Java, not C++.

Now I haven't read the other posts so maybe its already explained but... here:

You make two variables, suppose iMin, iMax.
Now tell your program that the Array's first value (iNumbers[0]) is minimum, as well as maximum. This is just a place from where your program can start.

Now, inside a for loop that executes 10 times, compare all values of iNumbers array to your iMin. If you come across a number that is less that iMin, update iMin (iMin=iNumbers[blah]).
Same goes for iMax.

If you want the code... you'll have to come up with it yourself :p
 
Last edited:

u0sama

Seasoned
Apr 12, 2009
4,683
1
43
33
karachi
u have two create two loops like this
for(int a=0;a<9;a++)
{
for(b=a+1;b<10;b++)
{
if(n[a]>n)
then swapping

n[0] will be minimum
n[9] will be maximum
 

Locust

I is a ninja =D
Feb 23, 2010
491
0
21
Lahore
and the winner this time is.....DRUM ROLL PLEASE!!!!!

ARSAL BHAI!!!!! *dances*

k yo i fugured it out...lab task 2 completed...ZING!!! =D

please stay tuned on saturday i come here with new amazing NOOBISH problems.. thanks to everyone again...

just in case

C++ Guru Score Count:-
Arsal 1
Mubaidr 1

xD
 

Crow

Seasoned
Jan 22, 2007
3,415
4
44
Haha, I've only done a C++ basic course in the first semester :p I can hardly be considered a guru.

But glad I could help.
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
  • funky funky:
    Hello
    Link
  • NaNoW NaNoW:
    by closing down good studios
    Link
  • NaNoW NaNoW:
    well he is breaking barriers
    • Like
    Reactions: KetchupBiryani
    Link
  • iampasha iampasha:
    SolitarySoldier said:
    Phil keeps talking about breaking barriers to gaming, making it accessible on all platforms yada yada, while killing competition and creativity at the same time. the fact that i actually believed him for a second lol
    guys the biggest yapper in the Industry right now. All he do is yap
    Link
  • Necrokiller Necrokiller:
    Phil should be held responsible for this shitfest too, just like Sarah, but it's highly likely that these decisions are coming from Satya. And this isn't even the end of it. More closures are coming.
    Link
  • SolitarySoldier SolitarySoldier:
    if we are moving towards more and more popular trash across platforms that make billions for companies, I'm happy with all the barriers and exclusivity because at least that brings some pressure to create good stuff.
    Link
  • SolitarySoldier SolitarySoldier:
    Phil keeps talking about breaking barriers to gaming, making it accessible on all platforms yada yada, while killing competition and creativity at the same time. the fact that i actually believed him for a second lol
    Link
  • SolitarySoldier SolitarySoldier:
    "These changes are not a reflection of the creativity and skill of the talented individuals at these teams or the risks they took to try new things" ... seems to me that's exactly what it is
    Link
  • SolitarySoldier SolitarySoldier:
    why make good games when u can just buy everyone and shut them down lol
    Link
  • XPremiuM XPremiuM:
    I'm gonna say one last time, F*** Microsoft to infinity!
    Link
  • XPremiuM XPremiuM:
    Microsoft deserves all the hate they can get. Seriously i can't explain how much i want to curse them out.
    Link
  • XPremiuM XPremiuM:
    They could've sold the studios instead of closing them, but the nazi bastards just didn't want competition down the road.
    Link
  • Link
  • XPremiuM XPremiuM:
    F*** Microsoft, and F*** their fanboys.
    Link
  • XPremiuM XPremiuM:
    What's the f*** is wrong with them? I mean really? Have they completely lost it? F***ing retards.
    Link
  • XPremiuM XPremiuM:
    So i just found out that f***ing s***bag Microsoft shut down Arkane Studio (makers of the brilliant Dishonored series) and Tango Gameworks (makers of the iconic The Evil Within series), among some other studios. I just want to say a giant F*** Y**! to Microsoft. THEY'VE F***ED UP BIG TIME this time.
    Link
  • Necrokiller Necrokiller:
    MS: Hold my trillion dollars
    Link
  • Necrokiller Necrokiller:
    Sony: We can f**k up a totally good situation.
    Link
  • Link
  • XPremiuM XPremiuM:
    Started Dead Island 2, and i find it pretty lame. The story is shit. The characters are either cringe or bland (all 6 of them), The gameplay isn't fun. Even the goddamn zombies don't behave like proper zombies. They're all fast & intelligent unlike how zombies are supposed to be like. Any fan of "zombie" genre cannot possibly like this shitfest of a game. Dying Light 2 was million times better than this shit.
    Link
  • NaNoW NaNoW:
    so Baldurs Gate 3 is pretty great!"
    Link
  • faraany3k faraany3k:
    So who here is waiting for Senua Hellblade 2. Prequel was a true mind fuck experience.
    Link
  • GloriousChicken GloriousChicken:
    Sad indeed
    Link
  • NaNoW NaNoW:
    what a sad day
    Link
  • faraany3k faraany3k:
    Necrokiller said:
    MS one upping Sony in catching the biggest L in gaming
    tbh gaming industry as a whole is failing much like tech industry. They have buckled down too much to Corporate suites then relying on passionate and innovative people. A corporate only believes in financial growth and shareholders.
    Link
    funky funky: Hello