Page 3 of 5

Re: Project 2

PostPosted: Mon May 04, 2009 6:37 am
by AntidotE
Huh, I can be wrong, but noone used ?: operator ;)

Code: Select all
// Proj2_Stat.cpp: Another 5 cents for this project solution...
// Best regards, AntidotE.

// Needed remark: "I... personally believe, thaaat..." (c) ;) 0 is non-positive and non-negative.

#include <iostream>
#include <cmath> //for using abs
using namespace std;

int main()
{
   int n1, n2;
   char ask = 'y';
   cout << "Hello, this is Project2 solution hereinafter named 'Stat'..." << endl << endl;
   cout << "  First of all, Stat'd like to note, that here is NO defence from fools :(" << endl;
   cout << "    That's why you have to be precisely sure what you are typing." << endl;
   do
   {
      cout << endl;
      cout << "Stat asks for FIRST number => ";
      cin >> n1;
      cout << "Stat asks for SECOND number => ";
      cin >> n2;
      cout << endl << "Stat answers: " << endl;
      
      cout << n1 << " and " << n2 << " are" << ( ( n1 != n2 ) ? " not " : " " ) << "equal!" << endl;
      cout << ( ( n1 > n2 ) ? n1 : n2 ) << " is > than " << ( ( n1 > n2 ) ? n2 : n1 ) << endl;
      cout << ( ( n1 < n2 ) ? n1 : n2 ) << " is < than " << ( ( n1 < n2 ) ? n2 : n1 ) << endl;
      cout << n1 << " is" << ( ( n1 >= n2 ) ? " " : " not " ) << ">= than " << n2 << endl;
      cout << n1 << " is" << ( ( n1 <= n2 ) ? " " : " not " ) << "<= than " << n2 << endl;
      cout << n1 << " is " << ( ( n1 % 2 ) ? "odd" : "even" ) << endl;
      cout << n2 << " is " << ( ( n2 % 2 ) ? "odd" : "even" ) << endl;
      cout << n1 << " is " << ( ( n1 > 0 ) ? "positive" : ( ( n1 < 0 ) ? "negative" : "zero" ) ) << endl;
      cout << n2 << " is " << ( ( n2 > 0 ) ? "positive" : ( ( n2 < 0 ) ? "negative" : "zero" ) ) << endl;
      cout << "difference between " << n1 << " and " << n2 << " is " << abs( ( n1 > n2 ) ? ( n2 - n1 ) : ( n1 - n2) ) << endl;
      cout << n1 << " / " << n2 << " = " << (double)( (double)n1 / (double)n2 ) << endl;
      cout << n2 << " / " << n1 << " = " << (double)( (double)n2 / (double)n1 ) << endl;

      cout << endl;
      cout << "Stat asks: 'Would you like to try one more time?'" << endl;
      cout << "  ('y' is yes, everything else is no) => ";
      cin >> ask;
   } while ( ask == 'y' );
   return 0;
}


and some example of output:
Code: Select all
Hello, this is Project2 solution hereinafter named 'Stat'...

  First of all, Stat'd like to note, that here is NO defence from fools :(
    That's why you have to be precisely sure what you are typing.

Stat asks for FIRST number => 5
Stat asks for SECOND number => -8

Stat answers:
5 and -8 are not equal!
5 is > than -8
-8 is < than 5
5 is >= than -8
5 is not <= than -8
5 is odd
-8 is even
5 is positive
-8 is negative
difference between 5 and -8 is 13
5 / -8 = -0.625
-8 / 5 = -1.6

Stat asks: 'Would you like to try one more time?'
  ('y' is yes, everything else is no) =>

Re: Project 2

PostPosted: Mon May 04, 2009 6:49 am
by antiRTFM
cool use of ?:

though as you can see, it can sometimes be unhelpful to code clarity and cleanliness. use with caution.

Re: Project 2

PostPosted: Mon May 04, 2009 8:03 am
by AntidotE
antiRTFM wrote:cool use of ?:

though as you can see, it can sometimes be unhelpful to code clarity and cleanliness. use with caution.


surely, I understand it :) and before putting it into one line, I write (keep in mind) something like this:
Code: Select all
( n1 % 2 ) ?   // is result in () "not 0" (means true)?
  ( "odd" )  : // yes it is true!
  ( "even" ) ; // no, it's false ("0")!

then write it this way:
Code: Select all
( n1 % n2 ) ? ( "odd" ) : ( "even" )

and put it wherever it needed to be used...

also, I keep in mind, that "?:" can return only one type (it is defined by "true" section), so the following code cannot be compiled:
Code: Select all
( n1 % n2 ) ? ( "odd" ) : ( 10 ) // WRONG!!!


if structure is more complicated, then I continue to use indentations:
Code: Select all
( n1 > 0 ) ?         // is this true?
   ( "positive" ) :  // yes!
   ( ( n1 < 0 ) ?    // no! Let's check another! is this true?
         "negative" :  // yes!
         "zero" )      // no!


generally, brackets (err, I hope, I named "()" correctly, my English is so far from even advanced...) help out:
Code: Select all
( ( n1 > 0 ) ? ( "positive" ) : ( ( n1 < 0 ) ? "negative" : "zero" ) )

Re: Project 2

PostPosted: Wed Jun 10, 2009 7:12 pm
by burgert
im new to c++ this is what i came up with but i don't know how to get a floating point number from the devision of two integers

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    int num1, num2;
    bool mainBool = true;
    string chose;


    cout << "enter a number" << endl;
    cin >> num1;
    cout << "enter a number" << endl;
    cin >> num2;

    if (num1 == num2)
    {
        cout << "numbers are equal" << endl;
    }
    else
    {
        if (num1 > num2)
        {
            cout << num1 << " is greater than " << num2 << endl;
            cout << num2 << " is less than " << num1 << endl;
        }
        else
        {
            cout << num2 << " is greater than " << num1 << endl;
            cout << num1 << " is less than " << num2 << endl;
        }
    }

    if (num1 % 2 == 0)
    {
        cout << num1 << " is even " << endl;
    }
    if (num2 % 2 == 0)
    {
        cout << num2 << " is even " << endl;
    }
    if (num1 >= 0 )
    {
        cout << num1 << " is positive " << endl;
    }
    else
    {
        cout << num1 << " is negative " << endl;
    }
    if (num2 >= 0)
    {
        cout << num2 << " is positive " << endl;
    }
    else
    {
        cout << num2 << " is negative " << endl;
    }

    cout << "the difference is " << endl;
    if (num1 > num2)
    {
        cout << num1 - num2 << endl;
    }
    else if (num1 == num2)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << num2 - num1 << endl;
    }






    }










Re: Project 2

PostPosted: Tue Jun 23, 2009 1:09 pm
by pipey85
burgert wrote:im new to c++ this is what i came up with but i don't know how to get a floating point number from the devision of two integers



I literally just read how to to that :)

you need to prefix your int variables with the type you wish to change it to...... for example .....

Code: Select all
int a = 5;
int b = 2;

cout << (float)a / (float)b;





This will change 'a' and 'b' into floating point types before the calculation is made, im really new to c++ myself so i cant tell you how it works exactly, suffice to say it works :P
good luck!

edit: forgot i came here to put my efforts of project 2 up for everyone to see. Here it is...

Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
   int num1;
   int num2;
   char restart;

   cout << "Welcome to the number statistics program" << endl;
   cout << "Please give me a number.....\n";
   cin >> num1;
   cout << "And a second number to compare to.....\n";
   cin >> num2;

   cout << endl << endl;



if (num1 != num2)
   cout << "Good, you picked two different numbers.\n";
else
   cout <<"The numbers you picked are the same.\n";



if (num1 < num2)
   cout << num2 << " is greater than " << num1 << endl;
else
   cout << num1 << " is greater than " << num2 << endl;

if (num1 > num2)
   cout << num2 << " is less than " << num1 << endl;
else
   cout << num1 << " is less than " << num2 << endl;

if (num1 >= num2)
   cout << num1 << " is greater than or equal to " << num2 << endl;
else
   cout << num1 << " is not greater than or equal to " << num2 << endl;

if (num2 >= num1)
   cout << num2 << " is more than or equal to " << num1 << endl;
else
   cout << num2 << " is not more than or equal to " << num1 << endl;

if (num1 <= num2)
   cout << num1 << " is less than or equal to " << num2 << endl;
else
   cout << num1 << " is not less than or equal to " << num2 << endl;

if (num2 <= num1)
   cout << num2 << " is less than or equal to " << num1 << endl;
else
   cout << num2 << " is not less than or equal to " << num1 << endl;

if (num1 % 2)
   cout << num1 << " is odd" << endl;
else
   cout << num1 << " is even" << endl;

if (num2 % 2)
   cout << num2 << " is odd" << endl;
else
   cout << num2 << " is even" << endl;

if (num1 >= 0)
   cout << num1 << " is positive" << endl;
else
   cout << num1 << " is negative" << endl;

if (num2 >=0)
   cout << num2 << " is positive" << endl;
else
   cout << num2 << " is negative" << endl;

if (num1 <= num2)
   cout << "The difference between these two numbers is " << (num2 - num1) << endl;
else
   cout << "The difference between these two numbers is " << (num1 - num2) << endl;

cout << num1 << '/' << num2 << '=' << ((float)num1 / (float)num2) << endl;
cout << num2 << '/' << num1 << '=' << ((float)num2 / (float)num1) << endl << endl << endl;

cout << "Would you like to start the program again to test two different numbers [y/n]?" << endl;
cin >> restart;

if (restart == 'y')
   main();



int a;
cin >> a;
return 0;
}

Re: Project 2

PostPosted: Tue Jun 23, 2009 7:32 pm
by antiRTFM
pipey85: thats called "casting", you are casting an int to float. I speak about casting a bit in some video but i guess ill talk more about it some other time.

Everything looks great in your code- besides where you call main(). main() is a special function which is where your program begins. You dont call main() from within your code. Use loops instead (have you learned about loops yet?)

Re: Project 2

PostPosted: Wed Jun 24, 2009 9:13 am
by Adamp
Here's my version of the project:

Code: Select all
#include <iostream>
using namespace std;

int main()
{
   int value1;
   int value2;

   cout << "Enter first value: ";
   cin >> value1;

   cout << "Enter second value: ";
   cin >> value2;

   if (value1 == value2)
   {
      cout << "The values are equal.\n";
      cout << value1 << " = " << value2 << endl;
   }
   else if(value1 > value2)
   {
      cout << value1 << " is larger.\n" << value2 << " is smaller.\n";
      cout << value1 << " > " << value2 << endl;
   }
   else if(value1 < value2)
   {
      cout << value2 <<" is larger.\n" << value1 << " is smaller.\n";
      cout << value1 << " < " << value2 << endl;
   }

   if(value1 >= value2)
      cout << value1 << " >= " << value2 << endl;   
   if(value1 <= value2)   
      cout << value1 << " <= " << value2 << endl;
   
   if(!(value1 % 2))
      cout << value1 << " is even.\n";
   else
      cout << value1 << " is odd.\n";
   if(!(value2 % 2))
      cout << value2 << " is even.\n";
   else
      cout << value2 << " is odd.\n";

   if (value1 > 0)
      cout << value1 << " is positive.\n";
   else if (value1 < 0)
      cout << value1 << " is negative.\n";
   else
      cout << value1 << " is neither negative nor positive. It is 0.\n";

   if (value2 > 0)
      cout << value2 << " is positive.\n";
   else if (value2 < 0)
      cout << value2 << " is negative.\n";
   else
      cout << value2 << " is neither negative nor positive. It is 0.\n";


   cout << value1 << " - " << value2 << " = " << value1 - value2 << endl;
   cout << value2 << " - " << value1 << " = " << value2 - value1 << endl;

   cout << value1 << " / " << value2 << " = " << value1 / value2;
   if (value1 % value2)
      cout << " remainder " << value1 % value2 << endl;
   else
      cout << endl;

   cout << value2 << " / " << value1 << " = " << value2 / value1;
   if (value2 % value1)
      cout << " remainder " << value2 % value1 << endl;
   else
      cout << endl;

   char f;
   cin >> f;
   return 0;
}

Re: Project 2

PostPosted: Sat Jun 27, 2009 2:29 pm
by pipey85
Thanks for the pointer antiRTFM, ive had a busy couple of days and im just picking up loops at the moment.

Re: Project 2

PostPosted: Sun Jun 28, 2009 4:20 pm
by realgamer686
One hr. i am done




Code: Select all
#include "stdafx.h"



#include <iostream>
#include <cmath>

using namespace std;

int main()
{
   int FirstNumber;
   int SecondNumber;
   

   cout << "Please enter your first number: ";
   cin >> FirstNumber;
   cout << "Please enter your second number: ";
   cin >> SecondNumber;

   cout << "\nTEST 1: Greater or Less than. \n" << endl;

   if (FirstNumber == SecondNumber)
   {
      cout << "They are equal \n" << endl;
      cout << FirstNumber << " is equal to " << SecondNumber << endl;
   }
   else
   {
      cout << "They are not equal" << endl;

      if (FirstNumber < SecondNumber)
      {
         cout << FirstNumber << " is less than or equal to " << SecondNumber << endl;
      }
      
      if (FirstNumber > SecondNumber)
      {
         cout << FirstNumber << " is greater than or equal to " << SecondNumber << endl;
      }
   }

   cout << "\nClick Enter to begain Test 2 ..." << endl;
   system ("pause");

   cout << "\nTEST 2: Even or Odd. \n" << endl;
   
   if ((FirstNumber % 2) == 0)
   {
      cout << "The first number (" << FirstNumber <<") your enter is EVEN" <<endl;
   }
   else
   {
      cout << "The first number (" << FirstNumber <<") your enter is ODD" <<endl;
   }

if ((SecondNumber % 2) == 0)
   {
      cout << "The second number (" << SecondNumber <<") your enter is EVEN" <<endl;
   }
   else
   {
      cout << "The second number (" << SecondNumber <<") your enter is ODD" <<endl;
   }

cout << "\nClick Enter to begain Test 3 ..." << endl;
system ("pause");

cout << "\nTEST 3: Positive or Negative. \n" << endl;

if (FirstNumber > 0)
   {
      cout << "The first number (" << FirstNumber <<") your enter is POSITIVE" <<endl;
   }
   else
   {
      cout << "The first number (" << FirstNumber <<") your enter is NEGATIVE" <<endl;
   }

if (SecondNumber > 0)
   {
      cout << "The second number (" << SecondNumber <<") your enter is POSITIVE" <<endl;
   }
   else
   {
      cout << " The second number (" << SecondNumber <<") your enter is NEGATIVE" <<endl;
   }

cout << "\nClick Enter to begain Test 4 ..." << endl;
system ("pause");

cout << "\nTEST 4: Difference and dividing. \n" << endl;

cout << "(" << FirstNumber << ")" << " - " << "(" << SecondNumber << ")" <<  " = " << FirstNumber - SecondNumber << endl;

double a;
double b;

a = FirstNumber;
b = SecondNumber;


cout << "(" <<a << ")" << " / " << "(" << b << ")" << " = " << a/b << endl;


char YN;

cout << "\nAll test are complete, do you like to test again (y/n)" << endl;
cin >> b;

if ( YN == 'y')
{
   cout << "" << endl;
   return main();
}

else
{
   return 0;
}

   char f;
   cin >> f;
   return 0;
}

Re: Project 2

PostPosted: Sun Jun 28, 2009 4:48 pm
by antiRTFM
@realgamer686: Good job! just one thing: you don't call main(). Ever. :)
Wait till you learn about loops.

Re: Project 2

PostPosted: Mon Jun 29, 2009 1:19 am
by davidemil55
Code: Select all
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
   
    int firstnumber;
    int secondnumber;
   
    cout << "Please input a number:";
    cin >> firstnumber;
    cout << "Please input another number:";
    cin >> secondnumber;
   
    if (firstnumber < secondnumber){
    cout << firstnumber <<" is greater then\n" << secondnumber;}
    if (secondnumber < firstnumber){
      cout << secondnumber <<" is greater then\n" << firstnumber;}
    if (firstnumber == secondnumber){
           cout << firstnumber <<" is equal too\n"<< secondnumber;}
    if (firstnumber < 0)
                cout << firstnumber << " is even\n";
    if ( firstnumber >0 )
                     cout << firstnumber << " is odd\n";
    if (secondnumber < 0)
                          cout << firstnumber << " is even\n";
    if ( secondnumber >0 )
                              cout << firstnumber << " is odd\n";
   
   
   
   
   
    if ((firstnumber % 2)== 0){
       cout << firstnumber <<" is even \n";}
       else {
       cout << "Number is odd";}
   
   
   
   
   
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

this is mine

Re: Project 2

PostPosted: Tue Jun 30, 2009 5:04 am
by realgamer686
build in Loop technology

Code: Select all
    #include "stdafx.h"



    #include <iostream>

    using namespace std;

    int main()
   {
      for (;;)
      {
         int FirstNumber;
         int SecondNumber;
      
          

         cout << "Please enter your first number: ";
         cin >> FirstNumber;
         cout << "Please enter your second number: ";
         cin >> SecondNumber;

         cout << "\nTEST 1: Greater or Less than. \n" << endl;

         if (FirstNumber == SecondNumber)
         {
           cout << "They are equal \n" << endl;
           cout << FirstNumber << " is equal to " << SecondNumber << endl;
         }
         else
         {
           cout << "They are not equal" << endl;
          

           if (FirstNumber < SecondNumber)
           {
             cout << FirstNumber << " is less than or equal to " << SecondNumber << endl;
           }
            
           if (FirstNumber > SecondNumber)
           {
             cout << FirstNumber << " is greater than or equal to " << SecondNumber << endl;
           }
         }

         cout << "\nClick Enter to begain Test 2 ..." << endl;
         system ("pause");

         cout << "\nTEST 2: Even or Odd. \n" << endl;
          
         if ((FirstNumber % 2) == 0)
         {
           cout << "The first number (" << FirstNumber <<") your enter is EVEN" <<endl;
         }
         else
         {
           cout << "The first number (" << FirstNumber <<") your enter is ODD" <<endl;
         }

      if ((SecondNumber % 2) == 0)
         {
           cout << "The second number (" << SecondNumber <<") your enter is EVEN" <<endl;
         }
         else
         {
           cout << "The second number (" << SecondNumber <<") your enter is ODD" <<endl;
         }

      cout << "\nClick Enter to begain Test 3 ..." << endl;
      system ("pause");

      cout << "\nTEST 3: Positive or Negative. \n" << endl;

      if (FirstNumber > 0)
         {
           cout << "The first number (" << FirstNumber <<") your enter is POSITIVE" <<endl;
         }
         else
         {
           cout << "The first number (" << FirstNumber <<") your enter is NEGATIVE" <<endl;
         }

      if (SecondNumber > 0)
         {
           cout << "The second number (" << SecondNumber <<") your enter is POSITIVE" <<endl;
         }
         else
         {
           cout << " The second number (" << SecondNumber <<") your enter is NEGATIVE" <<endl;
         }

      cout << "\nClick Enter to begain Test 4 ..." << endl;
      system ("pause");

      cout << "\nTEST 4: Difference and dividing. \n" << endl;

      cout << "(" << FirstNumber << ")" << " - " << "(" << SecondNumber << ")" <<  " = " << FirstNumber - SecondNumber << endl;

      double a;
      double b;

      a = FirstNumber;
      b = SecondNumber;

      cout << "(" <<a << ")" << " / " << "(" << b << ")" << " = " << a/b << endl;


      char c;

      cout << "\nAll test are completed. do you like to test again? (y/n)";
      cin >> c;
      cout << "" << endl;

      if( c  == 'y')
      {
         continue;
      }
      else
      {
         break;
         return 0;
      }
   }
}

Re: Project 2

PostPosted: Fri Jul 03, 2009 7:34 pm
by Silvershaft
Here is my second project, sorry about calling main() but I havent got so far in videos yet for loops. I know they are like for (a; a < 30; a++) {etc,etc} and while loop which name makes sense like while something is happening do something :)

Here is code (bit long)

Code: Select all
#include "stdafx.h"

#include <iostream>
#include <string>

using namespace std;

int main()
{
   int Number1;
   int Number2;
   system("Color 9");
   int startagain();



   cout << "Hello and welcome to my second project.\nThis will tell you something about two numbers that you type in." << endl;
   cout << "Enter your first number ( It can be also negative ): ";
   cin >> Number1;
   cout << "First number entered! Enter second one now: ";
   cin >> Number2;
   cout << "Okay, both numbers are entered here are some facts about them" << endl;
   cout << endl;
   cout << endl;



   if ( Number1 > Number2 )
   {
      cout << "-First number " <<"( " << Number1 << " ) is bigger than second number " << "( " << Number2 << " )" << endl;
   }
   else if ( Number2 > Number1 )
   {
      cout << "-Second number " <<"( " << Number2 << " ) is bigger than first number " << "( " << Number1 << " )" << endl;
   }
   else if ( Number1 == Number2 )
   {
      cout << "-First number " <<"( " << Number1 << " ) and second number " << "( " << Number2 << " )" << " equals" << endl;
   }




   if ( Number1 < Number2 )
   {
      cout << "-First number " <<"( " << Number1 << " ) is smaller than second number " << "( " << Number2 << " )" << endl;
   }
   else if ( Number2 < Number1 )
   {
      cout << "-Second number " <<"( " << Number2 << " ) is smaller than first number " << "( " << Number1 << " )" << endl;
   }




   if ( Number1 <= Number2 )
   {
      cout << "-First number " <<"( " << Number1 << " ) is less than or equals second number " << "( " << Number2 << " )" << endl;
   }
   else if (Number2 <= Number1 )
   {
      cout << "-Second number " <<"( " << Number2 << " ) is less than or equals first number " << "( " << Number1 << " )" << endl;
   }



   if ( Number1 >= Number2 )
   {
      cout << "-First number " <<"( " << Number1 << " ) is greater than or equals second number " << "( " << Number2 << " )" << endl;
   }
   else if ( Number2 >= Number1 )
   {
      cout << "-Second number " <<"( " << Number2 << " ) is greater than or equals first number " << "( " << Number1 << " )" << endl;
   }

   if ( (Number1 % 2) == 0 )
   {
      cout << "-First number " << "( " << Number1 << " )" << " is even" << endl;
   }
   else
   {
      cout << "-First number " << "( " << Number1 << " )" << " is odd" << endl;
   }





   if ( (Number2 % 2) == 0 )
   {
      cout << "-Second number " << "( " << Number2 << " )" << " is even" << endl;
   }
   else
   {
      cout << "-Second number " << "( " << Number2 << " )" << " is odd" << endl;
   }



   if ( Number1 < 0 )
   {
      cout << "-First number " << "( " << Number1 << " )" << " is negative" << endl;
   }
   else
   {
      cout << "-First number " << "( " << Number1 << " )" << " is positive" << endl;
   }


   if ( Number2 < 0 )
   {
      cout << "-Second number " << "( " << Number2 << " )" << " is negative" << endl;
   }
   else
   {
      cout << "-Second number " << "( " << Number2 << " )" << " is positive" << endl;
   }


   if ( Number1 > Number2 )
   {
      cout << "-The difference between these two number is " << Number1 - Number2 << endl;
   }
   else
   {
      cout << "-The difference between these two number is " << Number2 - Number1 << endl;
   }

   
   
   cout << "-First number " <<"( " << Number1 << " ) divided by second number " << "( " << Number2 << " )" << " is " << Number1 << " / " << Number2 << " = " << ((double) Number1 / Number2) << endl;
   cout << "-Second number " <<"( " << Number2 << " ) divided by first number " << "( " << Number1 << " )" << " is " << Number2 << " / " << Number1 << " = " << ((double) Number2 / Number1) << endl;
   startagain();
}

   int startagain()
   {
      string answer;

      cout << "Do you want to start again? ( Yes or no ) ";
      cin >> answer;

      if ( answer == "yes" || answer == "Yes" )
      {
         main();
      }
      else if ( answer == "no" || answer == "No" )
      {
         goto End;
      }
      else if ( answer != "yes" && answer != "no" )
      {
         cout << "Please give proper command!" << endl;
         startagain();
      }


End:

   return 0;

   }

Re: Project 2

PostPosted: Fri Jul 10, 2009 11:17 pm
by xyzmax
#include "stdafx.h"
#include <iostream>

using namespace std;


int a;
int b;


int main ()
{


cout << "Input first integer number: ";
cin >> a;
cout << "Input second integer number: ";
cin >> b;

if (a == b)
{
cout << a << " is equal to " << b; }

if ( a != b)
{
if ( a <= b)
{
cout << b << " is greater than " << a << endl; }
if ( a >= b)
{
cout << a << " is greater than " << b << endl; }
}


if ( (a % 2) == 0 )
{
cout << a << " is even number" << endl; }
else
{
cout << a << " is odd number" << endl; }

if ( (b % 2) == 0 )
{
cout << b << " is even number" << endl; }
else
{
cout << b << " is odd number" << endl; }


if ( a < 0) { cout << a << " is negative" << endl;}
else { cout << a << " is positive" << endl;}
if ( b < 0) { cout << b << " is negative" << endl;}
else { cout << b << " is positive" << endl;}


if ( a <= b)
{
cout << "The difference between " << a << " and " << b << " is " << b-a << endl;}
else {cout << "The difference between " << a << " and " << b << " is " << a-b << endl;}

double e;
e = a/b;
cout << a << " divided " << b << " is " << e;
cout << " and the remainder is " << a%b <<endl;




char z;
cout << "Please type (X) to continue: ";
cin >> z;

return 0;
}




****** Note: Please review my codes. One thing I cant get it to do is that if first number is small than second one and try to divide; it'll come out to be zero. I have used float and double, still it didnt work. :( I just start programming 2 days ago. I did this only after I viewed 23 tutorials. I have seen others code, they seem to be more advance than mine. Am I not getting it, or they saw more of the tutorials. I also felt that I used too many 'if'; if you can clean it up a little for me to gain better understandings. Thanks,

Re: Project 2

PostPosted: Fri Jul 10, 2009 11:20 pm
by xyzmax
if you can email me it'll be good. Thanks again, Please comments!!! :)