There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
newbie at C


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
snowdog's Avatar
Member with 72 posts.
 
Join Date: Apr 2003
Location: Edmonton, AB, Canada
19-Jun-2003, 01:28 AM #1
newbie at C
I'm a complete newbie using C, taking an introductory course through a local college (so my total C experience has been 4 weeks). The problem is this looping (if else if) assignment that's been giving me grief for a couple days now. This is what the output should look like...

100 is divisible by 4, but not by 3
101 is not divisible by 3 or by 4
102 is divisible by 3, but not by 4
103 is not divisible by 3 or by 4
104 is divisible by 4, but not by 3
105 is divisible by 3, but not by 4
106 is not divisible by 3 or by 4
107 is not divisible by 3 or by 4
108 is the first number over 100 that is divisible by 3 AND 4!

This is what mine looks like...

100 is divisible by 4, but not by 3
101 is not divisible by 3 or by 4
102 is divisible by 3, but not by 4
103 is not divisible by 3 or by 4
104 is divisible by 4, but not by 3
105 is divisible by 3, but not by 4
106 is not divisible by 3 or by 4
107 is not divisible by 3 or by 4
107 is the first number over 100 that is divisible by 3 AND 4!

I can't for the life of me get that last line to say "108...".
I'm attaching my code (please, no beating me over how sloppy it might be :-) ). I'm NOT looking for any rewrites or "do it like this" stuff. Just a suggestion or two. I'm running Mandrake 9.1 with GCC 3.2.2, using Vi for an editor, on a not too shabby AthlonXP2000+, 512MB. Thanks guys.
Attached Files
File Type: txt loops.txt (599 Bytes, 41 views)
__________________
"One OS to rule them all, one Passport to find them,
DRM to bring them all and with the EULA bind them,
In the Land of Redmond, where the Shadows lie." -- Unknown
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
19-Jun-2003, 04:51 AM #2
I did a slight redesign, but it's still basically the same.
You should be able to use the attached example to fix yours though.

note: I didn't use variables for 3 and 4 for the example. I also used cout for printing. Also pardon the unbeautified code.
Attached Files
File Type: txt example.txt (574 Bytes, 37 views)

Last edited by Shadow2531 : 19-Jun-2003 05:02 AM.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
19-Jun-2003, 05:26 AM #3
This one has the variables for 3 and 4. The variables are used in the printing part also, so you can change the value of the variables without having to change the 3 and 4 in the print lines.
Attached Files
File Type: txt example2.txt (667 Bytes, 36 views)

Last edited by Shadow2531 : 19-Jun-2003 05:33 AM.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
19-Jun-2003, 06:22 AM #4
Found the problem in your code.

The ,num goes in the first printf, not the second.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
19-Jun-2003, 06:26 AM #5
Here is exactly what you asked for.
Attached Files
File Type: txt final.txt (599 Bytes, 38 views)

Last edited by Shadow2531 : 19-Jun-2003 06:32 AM.
snowdog's Avatar
Member with 72 posts.
 
Join Date: Apr 2003
Location: Edmonton, AB, Canada
19-Jun-2003, 08:59 AM #6
shadow, thanks for the help. I remember telling myself to put the , num in the first printf(), then of course once I told myself to do that, I didn't do it and just moved on. Thanks again.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
19-Jun-2003, 10:46 PM #7
No problem.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:55 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.