Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,208 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,323 people online right now. Registration is fast and FREE... Join Now!




c++ program Help

 
Reply to this topicStart new topic

c++ program Help

arslan_09
20 May, 2008 - 07:31 AM
Post #1

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 49


My Contributions
Write a C++ program which takes an integer as input, and displays its two factors. These factors should be 1 and that number itself, if input is a prime number, otherwise these factors should not include 1 and that number itself. You are NOT allowed to use if statement and for loop in this program.

there is no error in running the program but i don't get the right values.

CODE
//Question 2

#include <iostream>
using namespace std;
void main()
{
int x,y;
cout<<"Enter an Integer:";
cin>>x;
y=1;
while(y<x && x%y==0)
{
  
  cout <<y;
  cout <<"\n";
  cout <<x/y;
  cout <<"\n";
   y++;
}
}



please help me it is urgent.

This post has been edited by arslan_09: 20 May, 2008 - 07:54 AM
User is offlineProfile CardPM
+Quote Post

jeronimo0d0a
RE: C++ Program Help
20 May, 2008 - 08:09 AM
Post #2

D.I.C Head
**

Joined: 3 Mar, 2008
Posts: 141


My Contributions
You need to take the cout's out of the while loop and put them just after. Otherwise you just print one of every attempted factor pair. Then you need an int variable z that is = to x/y. Then cout the factors y and z.
Hope that helps,
Jeronimo
User is offlineProfile CardPM
+Quote Post

arslan_09
RE: C++ Program Help
20 May, 2008 - 08:17 AM
Post #3

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 49


My Contributions
QUOTE(jeronimo0d0a @ 20 May, 2008 - 09:09 AM) *

You need to take the cout's out of the while loop and put them just after. Otherwise you just print one of every attempted factor pair. Then you need an int variable z that is = to x/y. Then cout the factors y and z.
Hope that helps,
Jeronimo


thanks for your help can you please send the code.
User is offlineProfile CardPM
+Quote Post

arslan_09
RE: C++ Program Help
20 May, 2008 - 10:31 AM
Post #4

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 49


My Contributions
anyone please could help me
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: C++ Program Help
20 May, 2008 - 10:40 AM
Post #5

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 14,969



Thanked: 48 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
arslan_09, you've been told in another thread that we are not here to just give you code. Nobody is going to "send the code".

He gave you the answer, now try to implement it and show us what you have and where you're still having problems.

If you just want code. Please find another forum. We don't do people's homework for them here.
User is offlineProfile CardPM
+Quote Post

arslan_09
RE: C++ Program Help
20 May, 2008 - 11:00 AM
Post #6

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 49


My Contributions
QUOTE(skyhawk133 @ 20 May, 2008 - 11:40 AM) *

arslan_09, you've been told in another thread that we are not here to just give you code. Nobody is going to "send the code".

He gave you the answer, now try to implement it and show us what you have and where you're still having problems.

If you just want code. Please find another forum. We don't do people's homework for them here.



well the problem is when i enter a prime number it is fine but when i enter any other number it displays many factors i have tried what jeronimo0d0a said but it is same as before.
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: C++ Program Help
20 May, 2008 - 11:12 AM
Post #7

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,556



Thanked: 99 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Try taking a look at LCM on wikipedia smile.gif
User is offlineProfile CardPM
+Quote Post

arslan_09
RE: C++ Program Help
20 May, 2008 - 12:11 PM
Post #8

New D.I.C Head
*

Joined: 14 Apr, 2008
Posts: 49


My Contributions
QUOTE(gabehabe @ 20 May, 2008 - 12:12 PM) *

Try taking a look at LCM on wikipedia smile.gif


thanks
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 12:50PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month