Tuesday, July 28, 2009

Programming Help plz?

I am trying to write a program that asks for two integers and then finds the greatest common factor between them. IN C++





PLZ don’t tell me what to do because I am knew do this and I tried it many times by my self and it doesn’t work. Trust me


plz fix it





Thank you


........................


using System;


using System.Collections.Generic;


using System.Text;





namespace ConsoleApplication1


{


class Program


{


static void Main(string[] args)


{


#include %26lt;math.h%26gt;


#include %26lt;iostream%26gt;


using namespace std;


int factor(int a, int b);





int main()


{


int x, y;





cout %26lt;%26lt; "This program allows calculating the factor\n";


cout %26lt;%26lt; "Value 1: ";


cin %26gt;%26gt; x;


cout %26lt;%26lt; "Value 2: ";


cin %26gt;%26gt; y;





cout %26lt;%26lt; "\nThe Greatest Common factor of "


%26lt;%26lt; x %26lt;%26lt; " and " %26lt;%26lt; y %26lt;%26lt; " is " %26lt;%26lt; factor(x, y) %26lt;%26lt; endl;





return 0;


}





int factor(int a, int b)


{


int ret_val=0;





/* CASE 1 a %26gt; b */


if (a %26gt; b)


{


ret_val = a/b;


}


else /* CASE 2 b %26gt;= a */


{


ret_val = b/a;


}





return (ret_val);


}


}


}

Programming Help plz?
not bad
Reply:pok
Reply:Move the #include lines to the top.
Reply:The problem is so easy!





Note that you can't place the Include command and using command in a function or subroutine body,





Place includes and usings in the first lines of your file, You will gain what you want!





Be Succeed,


Babax.
Reply:using System;


using System.Collections.Generic;


using System.Text;





namespace ConsoleApplication1


{


class Program


{


static void Main(string[] args)


{


#include %26lt;math.h%26gt;


#include %26lt;iostream%26gt;


using namespace std;


int factor(int a, int b);





int main()


{


int x, y;





cout %26lt;%26lt; "This program allows calculating your Dick size";


cout %26lt;%26lt; "Value 1: ";


cin %26gt;%26gt; x;


cout %26lt;%26lt; "Value 2: ";


cin %26gt;%26gt; y;





cout %26lt;%26lt; "\nThe Greatest Length "


%26lt;%26lt; x %26lt;%26lt; " and " %26lt;%26lt; y %26lt;%26lt; " is " %26lt;%26lt; factor(x, y) %26lt;%26lt; endl;





return 0;


}





int factor(int a, int b)


{


int ret_val=0;





/* CASE 1 a %26gt; b */


if (a %26gt; b)


{


ret_val = a/b;


}


else /* CASE 2 b %26gt;= a */


{


ret_val = b/a;


}





return (retDAM_val);


}


}


}


No comments:

Post a Comment