The Mother Board

Motherboards.org forums. Free tech support, motherboard ID, and more.
It is currently Tue Sep 18, 2018 11:55 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Basic C++ question...
PostPosted: Wed Sep 15, 2004 5:23 pm 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
Hey guys, I just started C++, and I was wondering what would be a basic way to find the lowest and highest number when the user inputs 3 different integers. I know that in Visual Basic when you used an if statement you could do something like:

If ( int1 < int2 ) and ( int1 < int3 ) then

But in C++ I know that I can't use THEN, and I can't compare more than 2 numbers. Any idea how to do that with just a basic <iostream> ?

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Sep 15, 2004 6:36 pm 
Offline
Mobo-fu Master
Mobo-fu Master

Joined: Thu Jan 25, 2001 1:01 am
Posts: 19405
Location: 00000h - 0000Fh
VISUAL BASIC:


If ( int1 < int2 ) and ( int1 < int3 ) then
COUNTER = 1
END




Would be this in C/C++:



If ( int1 < int2 || int1 < int3 )
COUNTER == 1;

_________________
"Imagination is the only weapon in the war against reality." -Jules de Gautier

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 16, 2004 12:33 pm 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
Ok, that works great. I have one last problem with my program though. Here's my script:

#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main()
{
int int1, int2, int3, sum, ave, prod;

cout << "Please enter 3 integers: ";

cin >> int1 >> int2 >> int3;

sum = int1 + int2 + int3;

cout << "The sum is " << sum << endl;

ave = (int1 + int2 + int3) / 3;

cout << "The average is " << ave << endl;

prod = int1 * int2 * int3;

cout << "The product is "<< prod << endl;

if (int1 < int2 || int1 < int3)
cout << "The lowest is " << int1 << endl;

if (int2 < int1 || int2 < int3)
cout << "The lowest is " << int2 << endl;

if (int3 < int1 || int3 < int2)
cout << "The lowest is " << int3 << endl;

if (int1 > int2 || int1 > int3)
cout << "The highest is " << int1 << endl;

if (int2 > int1 || int2 > int3)
cout << "The highest is " << int2 << endl;

if (int3 > int1 || int3 > int2)
cout << "The highest is " << int3 << endl;

return 0;
}

Itdoes everything it's supposed to, but when I put in (for example) the numbers 3 5 and 9, it does the lowest and highest 2 times, when I just want it once, idea?

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 16, 2004 1:09 pm 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Tue May 11, 2004 11:18 pm
Posts: 2191
Location: Outworld
That's OR: ||

That's AND: &&


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 16, 2004 1:47 pm 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
Ahh, I thought something was wrong with that! :roll: Thanks for the help guys! :D

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 16, 2004 5:04 pm 
Offline
Mobo-fu Master
Mobo-fu Master

Joined: Thu Jan 25, 2001 1:01 am
Posts: 19405
Location: 00000h - 0000Fh
Its been awhile since I drabbled in programming. Thanks for the clarification.

_________________
"Imagination is the only weapon in the war against reality." -Jules de Gautier

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 16, 2004 6:06 pm 
Offline
Black Belt 1st Degree
Black Belt 1st Degree

Joined: Sun May 11, 2003 8:47 pm
Posts: 1486
Location: Omaha, NE
Crap, now I have another question. :? I want to come up with a script where the user inputs a 5-digit number, seperates the number into it's individual digits and prints the digits seperated from one another by 3 spaces each. Apparently the hint my book gives is, "Use the integer division and modulous operators." and it gives an example of what it should look like, if the user inputed 42339, then the program should print:

4 2 3 3 9

I think that the "integer division and modulous operators" have me confused. What do they have to do with it? Also, just overall I think, WHAT THE HECK? 8O I think that being gone and majorly sick, didn't help me at all... :cry:

_________________
Tono Sien


Love is the greatest conspiracy, by the most loving genius.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Sep 17, 2004 12:30 am 
Offline
Black Belt 2nd Degree
Black Belt 2nd Degree

Joined: Tue May 11, 2004 11:18 pm
Posts: 2191
Location: Outworld
In C integer division is the / operator. Integer remainder (modulus) is the % operator.

42339 / 10 = 4233
42339 % 10 = 9

4233 / 10 = 423
4233 % 10 = 3

etc.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group