C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 26th, 2006, 03:06 AM
Star Wise Star Wise is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 Star Wise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 13 sec
Reputation Power: 0
Need help with C++ program

I am writing this program, and I would like to know if the first part of it is correct, and if it is, I will be able to figure out the rest of the program. I know this is a "do while loop," I just want to be sure that I am doing it the right way. Here is the program.

#include <iostream.h>

void main()
{
int X, Y;

X = 36;
Y = 20:

while (X > Y)
{
X = X - Y;
Y = Y/2;
}
cout<<"X=" <<X<<" and Y =" <<Y<<end1;
}

========================================
/ HERE IS MY ANSWER
/========================================


#include <iostream.h>

void main()
{
int X, Y;

X = 36;
Y = 20:

while (X > Y)
{
X = 16;
Y = 8;
}
cout<<"X=" <<X<<" and Y =" <<Y<<end1;
}

Any help you can give me will be greatly appreciated.

Reply With Quote
  #2  
Old March 27th, 2006, 07:45 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 996 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2Folding Points: 878024 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 11 m 36 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
I'm not sure if I understand your question correctly. The code at the top is a valid program, that will run a certain calculation untol X is smaller than Y.
The second code is not the first iteration of the loop in the program!

You start out with X = 36, Y = 20
After one loop: X = 16 (36 - 20) and Y = 10 (20 / 2)
after second loop: X = 6 (16 - 10) and Y = 5 (10 / 2)
after third loop: X - 1 (6 - 5) and Y = 2 (10 / 2, integer style (rounded down))
there is no fourth loop, since X is now smaller than Y.
So output will be
Code:
X=1 and Y =2
Comments on this post
Star Wise agrees!
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 278

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Need help with C++ program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT