Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Project 2

Here are some projects of actual programs you can practice making.

Postby invertedsmerf on Wed Aug 27, 2008 3:58 pm

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

int main()
{
    int firstN, secondN;
    char responce = 'n';


    while (responce == 'n')
    {
    cout << "Please enter the first number: ";
    cin >> firstN;
    cout << "Please enter the second Number: ";
    cin >> secondN;
    cout << endl;

        if (firstN < secondN)                            // determins less than value
        {
            cout << firstN << " Is less than " << secondN << "." << endl << endl;
        }
            else if (firstN > secondN)                  // determins greather than value
            {
                cout << firstN << " is greater than " << secondN << "." << endl << endl;

            }
            else if (firstN == secondN)                 // determins equality
            {
            /**************************************
             * Instead of doing a second set
             * that would accomplish the same
             * thing I added the equality evaluation
             * in this step. It seems like a good
             * place for it.
             **************************************/
                cout << "The numbers are even." << endl << endl;
            }

        if ((firstN % 2 == 0) && (secondN % 2 == 0))    // determins even or odd values
        {
            cout << firstN << " is even. " << '\n' << secondN << " Is even."<< endl << endl;
        }
            else if ((firstN % 2 != 0) && (secondN % 2 == 0))
            {
                cout << firstN <<  " is odd. " << '\n' << secondN << " Is even." << endl << endl;
            }
            else if ((firstN % 2 == 0) && (secondN % 2 != 0))
            // else if ((firstN % 2 = 0) && (secondN% 2 != 0))
            {
                cout << firstN <<  " is even. " << '\n' << secondN <<  " Is odd." << endl << endl;
            }
            else if ((firstN % 2 != 0) && (secondN % 2 != 0))
            {
                cout << firstN << " is odd. " << '\n' << secondN << " Is odd." << endl << endl;
            }


            /************************
             * indentation for easyer
             * readability.
             ************************/
        if ((firstN >= 0) && (secondN >= 0))                   // both are positive
        {
            cout << firstN << " is a positive numer. " << '\n' <<
                    secondN << " is also a positive number." << endl << endl;
        }
            else if ((firstN <= -1) && (secondN <= -1))         // both are nevative
            {
                cout << firstN << " is a negative numer. " << '\n'
                     << secondN << " is also a negative number." << endl << endl;
            }
            else if ((firstN >= 0) && (secondN <= -1))          // 1st is positave, 2nd is negative
            {
                cout << firstN << " is a positive numer. " << '\n'
                     << " but " << secondN <<  " is a negative number." << endl << endl;
            }
            else if ((firstN <= -1) && (secondN >= 0))          // 1st is nigitave, 2nd is positave
            {
                cout << firstN << " is a negative numer. " << '\n'
                     << " but " << secondN <<  "  is a positive number." << endl << endl;
            }

        float differenceN;
        differenceN = (secondN - firstN);
        cout << "The defference between, " << firstN << " and " << secondN << " is: " << differenceN << endl << endl;



        cout << "exit?" << '\n' << "'y'es or 'n'o" << endl;
        cin >> responce;
     }
     return 0;
}
invertedsmerf
 
Posts: 7
Joined: Tue Aug 26, 2008 11:41 pm

Postby Marss++ on Wed Aug 27, 2008 6:27 pm

Your code looks good. :)

Welcome to the forum.
Keep posting your questions up here if you have them.
I'm a 15 year old kid who has his heart set on Programming.

Came here hoping to help so if you have any questions just ask!
Marss++
 
Posts: 149
Joined: Fri Jul 18, 2008 3:20 pm

Postby Strazku on Wed Aug 27, 2008 8:16 pm

This is a bit of code using the same concept as what this thread was originally for, but using Logical Operators. It's a smaller version of the actual program you asked for AntiRTFM, so... if any improvements could be made or any comments, please let me know :)



Code: Select all
#include <iostream>

int main()


{


   int fNum;
   int sNum;

   std::cout << "Hello and welcome to my integer statistics program! \n";
   std::cout << "Short Brief: \n";
   std::cout << "This is a short brief to let you know what types of information we're going to use. \n";
   std::cout << "First I'm going to ask you to choose 2 different numbers, \nand then i'm going to print out a few things such as,\nWhether they are equal or not, If they are not equal then \nwhich number is greater, ect ect.  You get the idea!  Enjoy! :)\n";
   std::cout << "Please, type in your first number: ";

   std::cin >> fNum;
   std::cout << "Excellent!\n";
   std::cout << "Now please choose a different number: ";
   std::cin >> sNum;

   if( fNum == sNum || fNum > sNum )
      std::cout << fNum << " is equal to or greater than. " << sNum << std::endl;
   else
      std::cout << fNum << " is not equal to and is lower than " << sNum << std::endl;

   if(fNum > 0 && fNum > sNum)
      std::cout << fNum << " Is possitive and greater than " << sNum;
   else
      std::cout << fNum << " is possitive and lower than " << sNum;
   if(!fNum == sNum && fNum > sNum)
      std::cout << fNum << " is not equal to and is not greater than " << sNum;


   char f;
   std::cin >> f;
   return 0;
}
Strazku
 
Posts: 16
Joined: Sat Aug 23, 2008 11:21 pm

Re: Project 2

Postby dbproguy on Sat Oct 25, 2008 12:20 am

Well here's mine, I could probably do better at the division part :|

Code: Select all
#include <iostream>

using namespace std;

int main()
{
   int num1;
   int num2;
   int diff;
   cout << "Please enter an integer: ";
   cin >> num1;
   cout << "Please enter another integer: ";
   cin >> num2;
   
   if (num1 == num2)
      cout << "\n" << num1 << " is equal to " << num2;
   else {
      cout << "\n" << num1 << " is not equal to " << num2;
      if (num1 > num2) {
         cout << "\n\n" << num1 << " is greater than " << num2;
         cout << "\n" << num2 << " is less than " << num1;
         diff = num1 - num2;
      } else {
         cout << "\n\n" << num2 << " is greater than " << num1;
         cout << "\n" << num1 << " is less than " << num2;
         diff = num2 - num1;
      }
   }

   if (num1 >= num2) {
      cout << "\n\n" << num1 << " is greater-or-equals " << num2;
      cout << "\n" << num2 << " is lesser-or-equals " << num1;
   } else {
      cout << "\n\n" << num2 << " is greater-or-equals " << num1;
      cout << "\n" << num1 << " is lesser-or-equals " << num2;
   }

   if ((num1 % 2) == 0)
      cout << "\n\n" << num1 << " is even";
   else
      cout << "\n\n" << num1 << " is odd";
   if ((num2 % 2) == 0)
      cout << "\n" << num2 << " is even";
   else
      cout << "\n" << num2 << " is odd";

   if (num1 >= 0)
      cout << "\n\n" << num1 << " is positive";
   else
      cout << "\n\n" << num1 << " is negative";
   if (num2 >= 0)
      cout << "\n" << num2 << " is positive";
   else
      cout << "\n" << num2 << " is negative";

   cout << "\n\nThe difference between " << num1 << " and " << num2 << " is " << diff;

   cout << "\n" << num1 << " divided by " << num2 << " is " << num1 / num2 << " " << num1 % num2 << "/" << num2;
   cout << "\n" << num2 << " divided by " << num1 << " is " << num2 / num1 << " " << num2 % num1 << "/" << num1;
   cout << "\n\nThanks for your participation!";
   cout << "\nType anything and press enter to exit.\n";
   char temp;
   cin >> temp;
}
dbproguy
 
Posts: 3
Joined: Fri Oct 24, 2008 11:36 pm

Re: Project 2

Postby dontposeme on Mon Jan 05, 2009 10:23 pm

Here is my attempt at this project. I hope that I did everything right and if you find something wrong I would be glad to hear it. Thanks.

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

int main()
{
char exit;
double one;
double two;
int int1;
int int2;

cout << "This is a number statistics machine.\n";
cout << "Enter two whole intergers below.\n";
cout << endl;

cout << "First: ";
cin >> one;
cout << endl;
cout << "Second: ";
cin >> two;
cout << endl;

if (one == two)
{
   cout << "They are equal.\n";
}
   else
   {
      cout << "They are not equal.\n";
   }


if (one > two)
{
   cout << one << " is greater than " << two << endl;
}
else
{
   if (one < two)
   {
      cout << one << " is less than " << two << endl;
   }
}


if (one >= two)
{
   cout << one << " is greater than or equal to " << two << endl;
}
else
{
   if (one <= two)
   {
      cout << one << " is less than or equal to " << two << endl;
   }
}

int1 = one;
int2 = two;

if ((int1 % 2) == 0)
{
   cout << one << " is even.\n";
}
else
{
   cout << one << " is odd.\n";
}


if ((int2 % 2) == 0)
{
   cout << two << " is even.\n";
}
else
{
   cout << two << " is odd.\n";
}


if (one < 0)
{
   cout << one << " is negative.\n";
}
else
{
   cout << one << " is positive.\n";
}


if (two < 0)
{
   cout << two << " is negative.\n";
}
else
{
   cout << two << " is positive.\n";
}

cout << one << " - " << two << " = " << one - two << endl;



if (two != 0)
{
   cout << one << " / " << two << " = " << one / two << endl;
}
else
{
   if (two == 0)
   {
      cout << "Cannot divide by zero.\n";
   }
}

if (one != 0)
{
   cout << two << " / " << one << " = " << two / one << endl;
}
else
{
   if (one == 0)
   {
      cout << "Cannot divide by zero.\n";
   }
}

cout << "\nType in x and press enter to exit.\n";
cin >> exit;
return 0;
}
dontposeme
 
Posts: 2
Joined: Mon Jan 05, 2009 6:28 pm

Re: Project 2

Postby adrian++ on Thu Jan 08, 2009 11:57 pm

Hey everyone. I know I haven't been active on the forum lately,forgive me for that. I tried this project out, and I hope you enjoy it.

Here's the link: http://rapidshare.com/files/181270806/Statitistics.cpp

Please comment. I would like to know your thoughts and opinions on this project. :P
adrian++
 
Posts: 11
Joined: Sun May 18, 2008 2:15 pm

Re: Project 2

Postby Tythyrn on Mon Jan 19, 2009 1:22 am

Here is my program!
Code: Select all
#include <iostream>

int num1;  //first number
int num2;  //second number

int main()
{
   std::cout << "This program compares to numbers entered by the user.\n";
   std::cout << "Please enter the first number: ";
   std::cin >> num1;  //gets first number
   std::cout << "Please enter the second number: ";
   std::cin >> num2;  //gets second number

   if(num1 == num2)  //sees if two numbers are the same
      std::cout << num1 << " is equal to " << num2 << ".\n";
   else
      std::cout << num1 << " is not equal to " << num2 << ".\n";

   if(num1 != num2)  //if not same it goes down here
      if(num1 < num2) //sees which number is less than the other
         std::cout << num1 << " is less than " << num2 << ".\n";
      else
         std::cout << num2 << " is less than " << num1 << ".\n";

   if(num1 >= num2) //sees if num1 is greater than or equal to num2
      std::cout << num1 << " is greater than or equal to " << num2 << ".\n";
   else
      std::cout << num1 << " is not greater than or equal to " << num2 << ".\n";

   if(num2 >= num1) //sees if num2 is greater than or equal to num1
      std::cout << num2 << " is greater than or equal to " << num1 << ".\n";
   else
      std::cout << num2 << " is not greater than or equal to " << num1 << ".\n";

   if(num1 <= num2) //sees if num1 is less than or equal to num2
      std::cout << num1 << " is less than or equal to " << num2 << ".\n";
   else
      std::cout << num1 << " is not less than or equal to " << num2 << ".\n";

   if(num2 <= num1) //sees if num2 is less than or equal to num1
      std::cout << num2 << " is less than or equal to " << num1 << ".\n";
   else
      std::cout << num2 << " is not less than or equal to " << num1 << ".\n";

   if(num1 % 2 == 0) //sees if num1 is even
      std::cout << num1 << " is even.\n";
   else
      std::cout << num1 << " is odd.\n";

   if(num2 % 2 == 0) //sees if num2 is even
      std::cout << num2 << " is even.\n";
   else
      std::cout << num2 << " is odd.\n";

   if(num1 >= 0) //sees if num1 is positive
      std::cout << num1 << " is positive.\n";
   else
      std::cout << num1 << " is negative.\n";

   if(num2 >= 0) //sees if num2 is positive
      std::cout << num2 << " is positive.\n";
   else
      std::cout << num2 << " is negative.\n";

   //subtracts num1 by num2
   std::cout << "The difference between " << num1 << " and " << num2 << " is " << num1 - num2 << ".\n";


   /*Heh.  Pretty sure this is bad practice
   but changing the integer numbers into
   float numbers like this was the only
   way I knew how to make the compiler
   stop yelling at me saying it is illegal
   for a float to do a modulus(modulos? Oh,well)
   operator.(lines 45 and 50). So I converted them here
   so they could have a decimal at the end and still
   make the hard to please compiler happy.*/
   float x = num1;
   float y = num2;

   std::cout << x << " divided by " << y << " = " << x/y <<".\n"; //divides the numbers
   std::cout << y << " divided by " << x << " = " << y/x <<".\n";

   std::cout << "Type in anything and press Enter to exit. Thank you!\n"; //last words

   char f;
   std::cin >> f; //exits program
   return 0;
}
Tythyrn
 
Posts: 2
Joined: Sun Jan 18, 2009 11:24 pm

Re: Project 2

Postby Griffin012cgh on Sun Feb 22, 2009 1:03 am

Finally did this one,

Code: Select all
// Number Statistics.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <limits>

void onInit();


using namespace std;

int main()
{
   int nNum1;
   int nNum2;
   string szRun;

   onInit();

   do
   {
      cout << "Enter the first number: ";

      while ( !( cin >> nNum1 ) )
      {
         cout << "That isn't a number!" << "\n";
         cout << "Renter the first number: ";
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(), '\n');
      }
      cin.ignore(numeric_limits<streamsize>::max(), '\n');

      cout << "Enter the second number: ";

      while ( !( cin >> nNum2 ) )
      {
         cout << "That isn't a number!" << "\n";
         cout << "Renter the second number: ";
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(), '\n');
      }
      cin.ignore(numeric_limits<streamsize>::max(), '\n');

      if ( nNum1 > nNum2 )
      {
         cout << nNum1 << " is greater than " << nNum2 << "\n";
      } if ( nNum1 < nNum2 )
      {
         cout << nNum1 << " is less than " << nNum2 << "\n";
      } else if ( nNum1 == nNum2 )
      {
         cout << nNum1 << " and " << nNum2 << " are equal" << "\n";
      }

      int nRemainder = nNum1 % 2;

      if ( nRemainder == 0 )
      {
         cout << nNum1 << " is even" << "\n";
      } else
      {
         cout << nNum1 << " is odd" << "\n";
      }

      nRemainder = nNum2 % 2;

      if ( nRemainder == 0 )
      {
         cout << nNum2 << " is even" << "\n";
      } else
      {
         cout << nNum2 << " is odd" << "\n";
      }

      if ( nNum1 > 0 )
      {
         cout << nNum1 << " is positive" << "\n";
      } else if ( nNum1 < 0 )
      {
         cout << nNum1 << " is negative" << "\n";
      } else if ( nNum1 == 0 )
      {
         cout << nNum1 << " is neither positive nor negative since it equals 0" << "\n";
      }

      if ( nNum2 > 0 )
      {
         cout << nNum2 << " is positive" << "\n";
      } else if ( nNum2 < 0 )
      {
         cout << nNum2 << " is negative" << "\n";
      } else if ( nNum2 == 0 )
      {
         cout << nNum2 << " is neither positive nor negative since it equals 0" << "\n";
      }

      int nSum;
      int nDifference;
      bool bFail;

      nSum = nNum1 + nNum2;
      if (nNum1 > nNum2)
         nDifference = nNum1 - nNum2;
      else
         nDifference = nNum2 - nNum1;
      
      
      cout << "The sum of " << nNum1 << " and " << nNum2 << " is " << nSum << "\n";
      cout << "The difference between " << nNum1 << " and " << nNum2 <<
            " is " << nDifference << "\n";
      cout << nNum1 << " / " << nNum1 << " = " << float(nNum1) / float(nNum2) << "\n";
      cout << nNum2 << " / " << nNum1 << " = " << float(nNum2) / float(nNum1) << "\n";

      cout << "Do you want to run again? (y/n): ";

      while ( (bFail = !( cin >> szRun )) || ( szRun[0] != 'y' ) && ( szRun[0] != 'Y' ) &&
         ( szRun[0] != 'n' ) && ( szRun[0] != 'N' ) && ( szRun[1] != '\0' ) )
      {
         if (bFail)
         {
            cout << "Enter a character!" << "\n";
            cout << "Do you want to run again? (y/n): ";
         } else if ( ( szRun[0] != 'y' ) && ( szRun[0] != 'Y' ) &&
         ( szRun[0] != 'n' ) && ( szRun[0] != 'N' ) && ( szRun[1] != '\0' ) )
         {
            cout << "Please enter y or n!" << "\n";
            cout << "Do you want to run again? (y/n): ";
         }
      }


   } while ( (szRun[0] == 'y' || szRun[0] == 'y') && szRun[1] == '\0' );

   return 0;
}

void onInit()
{
   cout << "-------- Number Statistics --------" << "\n";
   return;
}
¿?*¤»~Hôw Çåñ ï mï§§ ¥ôü ïf ¥ôü wôñ'± gô åwå¥~»¤*¿?

Image
Griffin012cgh
 
Posts: 10
Joined: Tue Feb 17, 2009 10:27 pm

Re: Project 2

Postby Forb on Mon Mar 09, 2009 8:16 pm

umm its a little more than the requirements but I'm sure others have done this as well, I've added a restart to it, so if u wanted to test it you wouldn't have to keep clicking the run button in your compiler program thing.

Code: Select all
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    //state my int's and my string
    string answer;
    int x;
    int y;

    //initial text
    cout << "if you enter two numbers, i will tell you if they are equal or not,\n";
    cout << "and if they are not if they are greater than or less than\n \n";
    do
    {
        cout << "First number please\n \n";
   
        //getting first number
        cin >> x;
        cout << endl;
        cout <<endl;
   
        //getting second number
        cout << "second number please \n \n";
        cin >> y;
        cout << endl;
        cout << endl;
   
        //the determination part of the program
        if(x == y)
        {
              cout << x <<  " equal to " << y;
              cout << endl;
        }
        else if(x >> y)
        {
              cout << x << " greater than " << y;
              cout << endl;
        }
       
        else if(x << y)
        {
              cout << x << " less than " << y;
              cout << endl;
        }
        cout << "restart\n";
        cin >> answer;
        cout << endl;
        cout << endl;
        cout << endl;
    }
    while(answer == "yes" || answer == "y" || answer == "yea" || answer == "yeah" || answer == "Y" || answer == "Yes" || answer == "Yea" || answer == "Yeah");

}
Forb
 
Posts: 8
Joined: Mon Mar 09, 2009 6:35 pm

Re: Project 2

Postby jwood1988 on Tue Apr 07, 2009 3:36 pm

This Project Was a Little More Difficult I struggled a little bit with the making fractional parts and the even and odd integers show up at the same time finally figured it out though.... because before i would get a compiler error...so i created a two float variables and set them equal to my regular integers and that solved my problem... Think i made a pretty good program for the project please comment if you see any mistakes


Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;
int main ()
{
   int x;
   int  y;
   int  z;
   float f;
   float g;
   
   
   cout << "Please Enter a Number:  \n";
   cin >> x ;
   cout << "Please Enter Another Number:  \n";
   cin >> y ;
   if(x == y)
      cout << "The Two Numbers:  "<<x<<"  And  " <<y<< "  Are Equal\n";
   else(x != y);
   {
      cout << "The Two Numbers:  "<<x<<"  And  " <<y<< "  Are Not Equal\n";
      if(x > y)
      {
         cout << x << "  Is Greater Than:  "<<y<<endl;
         cout << y << "  Is Less Than:  "<<x<<endl;
         z = x - y ;
         cout << " The Difference between  "<<x<<"  And  "<<y<< "  Is:   "<<z<<endl;
         



      }
      if(x < y)
      {
         cout << y << "  Is Greater Than:  "<<x<<endl;
         cout << x << "  Is Less Than:  "<<y<<endl;
         z = y - x ;
         cout << " The Difference between  "<<y<<"  And  "<<x<< "  Is:  "<<z<<endl;
         
      }
   }
   if(x % 2 == 0 )
      cout << x <<"  Is an Even Number.\n";
   else
      cout << x <<"  Is a Odd Number. \n";
   if(y % 2 == 0)
      cout << y <<"  Is an Even Number.\n";
   else
      cout << y <<"  Is an Odd Number. \n";
   if(x > 0 )
      cout << x <<"  Is a Positive Number.\n";
   else
      cout << x <<"  Is a Negative Number.\n";
   if(y > 0 )
      cout << y <<"  Is a Positive Number.\n";
   else
      cout << y <<"  Is a Negative Number.\n";
   
   f = x;
   g = y;
   cout << f << "  Divided by  "<< g << "  Is  "<< f / g <<endl;

   char j;
   cin >> j;
   return 0;
}
jwood1988
 
Posts: 2
Joined: Mon Apr 06, 2009 8:39 pm

Re: Project 2

Postby Laynk on Fri Apr 10, 2009 8:51 am

Ok, this is my second program ever (and first post), the first one was the calculator, so I would appreciate and criticism. What do you guys think?

EDIT: BTW: AntiRTFM I wanted to say I truly appreciate you helping us out and teaching us C++.


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

int _tmain(int argc, _TCHAR* argv[])
{
   int a;
   int b;
    // I know I should have used more easily identifiable variable names.
   //I'll make sure it doesn't become a habit.

   cout << "Weclome to the Stat-0-Tron 5000\n";
      cout << "Enter the first number you are interested in:   ";
      cin >> a;
      cout << "\nNow enter the second number you have in mind:   ";
      cin >> b;

                     //Greater than, less than, or equal to
         if (a != b)
            {   
               cout << a << " is not equal to " << b;
               cout << " because... ";
               if (a < b)
                  cout << a << " is less than " << b << endl;
               else
                  cout << a << " is greater than " << b << endl;
            }
         else    
            cout << a << " is equal to " << b << endl;

         
                     //evens or odds?
         if (a % 2 == 0)
            cout << a << " is an even number\n";
         else
            cout << a << " is an odd number\n";

         if (b % 2 == 0)
            cout << b << " is an even number\n";
         else
            cout << b << " is an odd number\n";


                     //positive, negative
         if (a < 0)
            cout << a << " is a negative number.\n";
         else
            cout << a << " is a positive number.\n";
         if (b < 0)
            cout << b << " is a negative number.\n";
         else
            cout << b << " is a positive number.\n";


                     //subtraction
         if (a > b)
            cout << "The difference between these numbers is: " << (a - b) << endl;
         else
            cout << "The difference between these numbers is: " << (b - a) << endl;


                     //division
         float y = a;
         float z = b;
         cout << a << " Divided by " << b << " equals: " << (y / z) << endl;
         cout << b << " Divided by " << a << " equals: " << (z / y) << endl;

         cout << "Press the 'any' key and Enter to exit.\n";
         
         //Thats a joke, btw.


   char f;
   cin >> f;
   return 0;
}
Laynk
 
Posts: 2
Joined: Wed Apr 08, 2009 6:18 am

i try my best xD

Postby vks++ on Sat Apr 25, 2009 2:32 pm

well i hope i did it right but the only problem is the division part i think.
can someone tell me what was i suppose to do with the fractions etc.
Code: Select all
#include<iostream>
using namespace std;

int main()
{
   int number;
   int numberone;

   cout<< "Please enter two integer number " << endl;
   cout<< endl;
   cout<< "First number: ";
   cin>> number;
   cout<< "Second number: ";
   cin>> numberone;
   cout<< endl;
   cout<< "Statics" << endl;

// Equal, greater, less,
if (number == numberone)
   cout<< number <<" is equal to " << numberone << endl;
else
   cout<< number << " is not equal to " << numberone << endl;
    if(number != numberone)
        cout<< numberone <<" is not equal to "<<number<< endl;
     else
        cout<< numberone <<" is equal to "<<number<<endl;
if (number >= numberone)
   cout<< number <<" is greater or equal to "<< numberone << endl;
else
   cout<< number <<" is not greater or equal to "<< numberone << endl;
    if (number >= numberone)
   cout<< numberone <<" is not greater or equal to "<< number << endl;
     else
   cout<< numberone <<" is greater or equal to "<< number << endl;

//Even or Odd number
if (number % 2 == 0)
   cout<< number << " is an even number "<<endl;
else
   cout<< number << " is an odd number " <<endl;

if (numberone % 2 == 0)
   cout<< numberone << " is an even number "<<endl;
else
   cout<< numberone << " is an odd number " <<endl;
// Divison
    cout<< number << " divided by "<< numberone << " = " << (number / numberone) << endl;
    cout<< numberone << " divided by "<< number << " = " << (numberone / number) << endl;


//Negative or Positive
if (number > 0)
    cout<< number << " is a positive number." << endl;
else
    cout<< number <<" is a negative number."<<endl;
if (numberone > 0)
    cout<< numberone << " is a positive number." << endl;
else
    cout<< numberone <<" is a negative number."<<endl;

//The difference between the two numbers

cout<< "The difference between " << number << " and "<<numberone<<" is "<< number - numberone << endl;
cout<< "The difference between " << numberone << " and "<<number<<" is "<< numberone - number << endl;

cin. get();
   return 0;
}

nvm i got it to work xD
i just added

float number;
float numberone;
int n;
n = number;
int t;
t = numberone;

and it work :D
User avatar
vks++
 
Posts: 3
Joined: Sat Apr 25, 2009 12:49 pm
Location: Georgia

Re: Project 2

Postby efrog57 on Sun Apr 26, 2009 2:44 am

Finally, after correcting so many mistakes, i think i got everything working as supposed to.

Code: Select all
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
   int x;
   int y;

   cout << "This program will evaluate and print out statistics about two number \n";

   cout << "Enter the first number: ";
   cin >> x;

   cout << "Enter the second number: ";
   cin >> y;

   if (x == y)
      cout << "The numbers are equal" << endl;
   
   if (x > y)
      cout << x << " is greater than " << y << endl;
      
   if (x < y)
      cout << x << " is lower than " << y << endl;

   if ((x % 2) == 0)
      cout << "The first number is even" << endl;
   else
      cout << "The first number is odd" << endl;

   if ((y % 2) == 0)
      cout << "The second number is even" << endl;
   else
      cout << "The second number is odd" << endl;

   if (x > 0)
      cout << "The first number is positive \n";
   else
      cout << "The first number is negative \n";

      if (y > 0)
      cout << "The second number is positive \n";
   else
      cout << "The second number is negative \n";


   if (x >= y)
   cout << "The difference between the two numbers is: " << x-y << endl;
   else cout << "The difference between the two numbers is: " << y-x << endl;

   double first;
   double second;

   first = x;
   second = y;

   cout << first << " divided by " << second << " = " << first/second << endl;
   cout << second << " divided by " << first << " = " << second/first << endl;   

   

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

efrog57
 
Posts: 13
Joined: Sat Apr 18, 2009 2:52 am

Re: Project 2

Postby daxxter on Sat May 02, 2009 10:45 am

Code: Select all
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
   int number1;
   int number2;
   float num1;
   float num2;

   cout << "Enter an integer: ";
   cin >> number1;
   cout << "Enter another integer: ";
   cin >> number2;

   if ( number1 == number2)
   {
      cout << number1 << " is equal to " << number2 << endl;
      cout << number1 << " is greater-or-equal to " << number2 << endl;
      cout << number1 << " is less-or-equal to " << number2 << endl;
   }
   if (number1 > number2)
   {
      cout << number1 << " is greater than " << number2 << endl;
      cout << number2 << " is less than " << number1 << endl;
      cout << number1 << " is greater-or-equal to " << number2 << endl;
      cout << number2 << " is not greater-or-equal to " << number1 << endl;
      cout << number2 << " is less-or-equal to " << number1 << endl;
      cout << number1 << " is not less-or-equal to " << number2 << endl;
   }
   if (number1 < number2)
   {
      cout << number2 << " is greater than " << number1 << endl;
      cout << number1 << " is less than " << number2 << endl;
      cout << number1 << " is not greater-or-equal to " << number2 << endl;
      cout << number2 << " is greater-or-equal to " << number1 << endl;
      cout << number1 << " is less-or-equal to " << number2 << endl;
      cout << number2 << " is not less-or-equal to " << number1 << endl;
   }
   if ((number1 % 2) == 0)
   {
      cout << number1 << " is even\n";
   }
   else
   {
      cout << number1 << " is odd\n";
   }

   if ((number2 % 2) == 0)
   {
      cout << number2 << " is even\n";
   }
   else
   {
      cout << number2 << " is odd\n";
   }
   if (number1 > 0)
   {
      cout << number1 << " is positive\n";
   }
   else
   {
      cout << number1 << " is negative\n";
   }
   if (number2 > 0)
   {
      cout << number2 << " is positive\n";
   }
   else
   {
      cout << number2 << " is negative\n";
   }
   if (number1 > number2)
   {
      cout << "the difference between the two numbers is " << number1 - number2 << endl;
   }
   else
   {
      cout << "the difference between the two numbers is " << number2 - number1 << endl;
   }
   cout << number1 << " / " << number2 << '=' << number1 / number2 << endl;
   cout << number2 << " / " << number2 << '=' << number2 / number1 << endl;
   num1 = number1;
   num2 = number2;
   cout << num1 << " / " << num2 << '=' << num1 / num2 << endl;
   cout << num2 << " / " << num1 << '=' << num2 / num1 << endl;



char f;
cin >>f;
return 0;
}
daxxter
 
Posts: 2
Joined: Thu Apr 30, 2009 8:54 pm

Re: Project 2

Postby Kobold on Sat May 02, 2009 5:27 pm

Hey there, this is my code

Code: Select all
#include "stdafx.h"


#include <iostream>

using namespace std;

int main()
{
   signed long number1;
   signed long number2;


   cout << "Enter an integer number please. \n";
   cin >> number1;

   cout << "Now enter another integer number. \n";
   cin >> number2;

   if ( number1 == number2 )
      cout << "They are equal \n";
   else
      cout << "They are not equal \n";

   if ( number1 != number2)
   {
      if ( number1 > number2)
      {   
         cout << number1;
         cout <<   " is greater than ";
         cout <<   number2 << endl;
      }
      else
      {
         cout << number1;
         cout << " is less than ";
         cout << number2 << endl;
      }
   }

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

   int x = number1 - number2;
   cout << "The diference between the two numbers is " << x << endl;

   double y = number1 / number2;
   cout << "The first number divided by the second one is " << y << endl;

   cout << "Please, press any key to finish this application";

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


If there is anything wrong, just mention it. I am here to learn :)
Kobold
 
Posts: 8
Joined: Sat May 02, 2009 5:20 pm

PreviousNext

Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests