Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Bah, I'm in Prog. class now
Closed Thread
Old 04-21-2005, 08:44 AM   #1 (permalink)
 
Ultra Techie

Join Date: Apr 2005

Posts: 721

SkyHi

Default Bah, I'm in Prog. class now

We literally started C++ 2 days ago, and my teacher knows nothing, we're supposed to do this program:

Write code that will multiply some number by 2 if the number is between 1 and 100 (including 1 or 100) and if it is evenly divisible by 3; otherwise multiply by 3 if it is between 1 and 100 but not divisible by 3; finally, if it isnÂ’t between 1 and 100, multiply the number by the number modulus 100. Hint: Use the nested if statement

Can anyone give me some starters? I know the basics, but how do you see if it's divisble by 3?? I can do it but it'd take like 15+ lines of code, is there a simple way?
ANY help is appreciated!
__________________
<center><font face=\"verdana, arial, helvetica\" size=\"2\" ><font size=1><a href=http://www.gogle.com>Google</a>«»<a href=http://www.userfrindly.org/>UFies</a>«»<a href=http://www.opea.com/download/><b>Get Opera 8.00</b></a>«»<a href=http://36.yahoo.com>Yahoo! 360!</a></font><table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"1\" bordercolor=\"#99FF00\"><tr><td bordercolor=\"#99FF00\"><tr><td bordercolor=\"#99FF00\"><strong><marquee behavior=\"alternate\" width=100% scrollamount=\"5\"><font color=#43525F size=\"1\"><font color=ff0000>«» <u>Computer - Science forum abuser!</u> «»</font></marquee></strong></td></tr><tr><td bordercolor=\"#485F8D\"><center><font size=\"1\"><font color=#FF00CC><b>Motherboard: </b></font><font color=#0000CC>MB GIGABYTE GA-K8N Ultra-9 <font color=#FF00CC><b><br>Chipset: </b></font><font color=#0000CC>NVIDIA nForce4 Ultra <font color=#FF00CC><b><br>Processor: </b></font><font color=#0000CC>CPU AMD 64 |3200+ ATHLON 939P 90 R <font color=#FF00CC><b><br>RAM: </b></font><font color=#0000CC>DDR CRSR 512MB X2 KIT|VS1GBKIT400 <font color=#FF00CC><b><br>Videocard: </b></font><font color=#0000CC>VGA EVGA|GF 6600GT 128-P2-N368-TX <font color=#FF00CC><b></b></font></a></font></td></tr></table><div align=center><font size=1 color=brown></font></div></font></p>
SkyHi is offline  
Old 04-21-2005, 09:41 AM   #2 (permalink)
 
Monster Techie

Join Date: Jul 2003

Posts: 1,179

Emily is on a distinguished road

Send a message via AIM to Emily
Default

You have to use an if else if else statement. To see if a number is divisible by 3, use the modulus operator (%). That returns the remainder, so if the remainder is 0, it is divisible by 3.
Quote:
if ((n>=1) and (n<=100) and (n%3 == 0)) {
n*=2;
} else if ((n>=1) and (n<=100)) {
n*=3;
} else {
n = n * (n%100);
}
Hope this helped.
__________________
<a href=\"http://www.upstark.com\">www.upstark.com</a>
Emily is offline  
Old 04-21-2005, 02:30 PM   #3 (permalink)
 
Ultra Techie

Join Date: Apr 2005

Posts: 721

SkyHi

Default

Thanks, but not really cuz I can't have it tell you modulus and THEN go on thanks though!!
__________________
<center><font face=\"verdana, arial, helvetica\" size=\"2\" ><font size=1><a href=http://www.gogle.com>Google</a>«»<a href=http://www.userfrindly.org/>UFies</a>«»<a href=http://www.opea.com/download/><b>Get Opera 8.00</b></a>«»<a href=http://36.yahoo.com>Yahoo! 360!</a></font><table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"1\" bordercolor=\"#99FF00\"><tr><td bordercolor=\"#99FF00\"><tr><td bordercolor=\"#99FF00\"><strong><marquee behavior=\"alternate\" width=100% scrollamount=\"5\"><font color=#43525F size=\"1\"><font color=ff0000>«» <u>Computer - Science forum abuser!</u> «»</font></marquee></strong></td></tr><tr><td bordercolor=\"#485F8D\"><center><font size=\"1\"><font color=#FF00CC><b>Motherboard: </b></font><font color=#0000CC>MB GIGABYTE GA-K8N Ultra-9 <font color=#FF00CC><b><br>Chipset: </b></font><font color=#0000CC>NVIDIA nForce4 Ultra <font color=#FF00CC><b><br>Processor: </b></font><font color=#0000CC>CPU AMD 64 |3200+ ATHLON 939P 90 R <font color=#FF00CC><b><br>RAM: </b></font><font color=#0000CC>DDR CRSR 512MB X2 KIT|VS1GBKIT400 <font color=#FF00CC><b><br>Videocard: </b></font><font color=#0000CC>VGA EVGA|GF 6600GT 128-P2-N368-TX <font color=#FF00CC><b></b></font></a></font></td></tr></table><div align=center><font size=1 color=brown></font></div></font></p>
SkyHi is offline  
Old 04-21-2005, 07:20 PM   #4 (permalink)
 
Monster Techie

Join Date: Jul 2003

Posts: 1,179

Emily is on a distinguished road

Send a message via AIM to Emily
Default

What do you mean?
__________________
<a href=\"http://www.upstark.com\">www.upstark.com</a>
Emily is offline  
Old 04-27-2005, 08:30 AM   #5 (permalink)
 
Ultra Techie

Join Date: Apr 2005

Posts: 721

SkyHi

Default

Emily, sorry about that, that works fine, Thanks.
__________________
<center><font face=\"verdana, arial, helvetica\" size=\"2\" ><font size=1><a href=http://www.gogle.com>Google</a>«»<a href=http://www.userfrindly.org/>UFies</a>«»<a href=http://www.opea.com/download/><b>Get Opera 8.00</b></a>«»<a href=http://36.yahoo.com>Yahoo! 360!</a></font><table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"1\" bordercolor=\"#99FF00\"><tr><td bordercolor=\"#99FF00\"><tr><td bordercolor=\"#99FF00\"><strong><marquee behavior=\"alternate\" width=100% scrollamount=\"5\"><font color=#43525F size=\"1\"><font color=ff0000>«» <u>Computer - Science forum abuser!</u> «»</font></marquee></strong></td></tr><tr><td bordercolor=\"#485F8D\"><center><font size=\"1\"><font color=#FF00CC><b>Motherboard: </b></font><font color=#0000CC>MB GIGABYTE GA-K8N Ultra-9 <font color=#FF00CC><b><br>Chipset: </b></font><font color=#0000CC>NVIDIA nForce4 Ultra <font color=#FF00CC><b><br>Processor: </b></font><font color=#0000CC>CPU AMD 64 |3200+ ATHLON 939P 90 R <font color=#FF00CC><b><br>RAM: </b></font><font color=#0000CC>DDR CRSR 512MB X2 KIT|VS1GBKIT400 <font color=#FF00CC><b><br>Videocard: </b></font><font color=#0000CC>VGA EVGA|GF 6600GT 128-P2-N368-TX <font color=#FF00CC><b></b></font></a></font></td></tr></table><div align=center><font size=1 color=brown></font></div></font></p>
SkyHi is offline  
Old 05-03-2005, 05:37 PM   #6 (permalink)
 
Ultra Techie

Join Date: Apr 2005

Posts: 950

M4A1 is on a distinguished road

Send a message via AIM to M4A1
Default

Yeah, it can seem confusing at times. The modulus operator basically tells you if x is divisble by y, it is only if it has no remainders. (x % y == 0) means that it is equally divisible. Have fun with C++, it's a great programming language.
M4A1 is offline  
 
Closed Thread

« Array | String »
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On