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.

Re: Project 2

Postby learning in progress on Sun Jul 12, 2009 2:04 pm

lol i tried to make it but came up with a integer Statistics program + a calculator
Code: Select all
#include "stdafx.h"

#include <iostream>

using namespace std;

int main ()
{
   double first;
   double second;
   double difference;
   double divide;
   double add;
   double multiply;
   char choice;
   cout << "The Integer Statstics Project:)!! \n";
   cout << "Please Enter your first Integer: \n";
   cin >> first;
   cout << "Please Enter your second Integer: \n" ;
   cin >> second;
   (first == second)? cout << first <<"   "<< "is equal to "<< "   "<< second : cout <<"They are not equal "<<endl;
   (first>second)? cout << first << "   "<<"is greater than "<<"   "<< second <<"\n"<< second<<"   " << "is less than" <<"   "<<first : cout <<second <<"is greater than "<<first<<"\n"<<first <<"is less than"<<second<< endl;
   (first>=second)? cout << first << "   "<<"is greater than or equal to"<<"   "<< second <<"\n"<< second<<"   " << "is not less than" <<"   "<<first : cout <<second <<"is greater than or equal to"<<first<<"\n"<<first <<"is less than or equal to"<<second<< endl;
   cout << "\n choose what do you want to do with two integers (+,-,*,/): \n";
   cin >> choice;
   difference=first-second;
   divide=first/second;
   add=first+second;
   multiply=first*second;
   if (choice=='+')cout << add;
   else if (choice =='-') cout << "The difference is"<<"    "<<difference;
   else if (choice == '*') cout << multiply;
   else if (choice == '/') cout << "The division result is" << "    "<<divide;
   char f;
   cin >> f;
   return 0;
}


sorry for mistakes i am just learning this thing :roll:
learning in progress
 
Posts: 11
Joined: Thu Jul 09, 2009 4:15 pm

Re: Project 2

Postby RobZ on Wed Jul 22, 2009 9:28 pm

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

int GetInt();
static bool IsEven(int x);
static bool IsEqual(int x, int y);
static bool IsPositive(int x);

void main()
{
   int x = GetInt();
   int y = GetInt();
   
   std::cout << std::endl << x << " & " << y << " are " << (IsEqual(x, y) ? "" : "not ") << "equal" << std::endl;

   if(!IsEqual(x,y))
   {
      std::cout << x << (x < y ? " is less than " : " is greater than ") << y << "." << std::endl
         << "The difference between them is: " << (x < y ? y-x : x-y) << "." << std::endl;
   }
   else
      std::cout << "The difference between them is: 0." << std::endl;

   std::cout << x << (IsEven(x) ? " is even." : " is odd.") << std::endl
      << y << (IsEven(y) ? " is even." : " is odd.") << std::endl
      << x << (IsPositive(x) ? " is positive." : " is negative.") << std::endl
      << y << (IsPositive(y) ? " is positive." : " is negative.") << std::endl
      << x << " / " << y << " = " << (float)x/y << std::endl
      << y << " / " << x << " = " << (float)y/x << std::endl
      << "\nPress any key and then Enter to exit." << std::endl;
   std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
   std::cin.get();
}

int GetInt()
{
   std::cout << "Please enter an integer: ";
   int x;
   std::cin >> x;
   return x;
}

static bool IsEven(int x)
{
   return (x & 1) == 0 ? true : false;
}

static bool IsEqual(int x, int y)
{
   return x == y ? true : false;
}

static bool IsPositive(int x)
{
   return x >= 0 ? true : false;
}


First program I've written. Only because I never have any ideas for projects. =o
Anything I'm doing majorly wrong?
Thank you very much for the tutorials, Great help!

Thanks.
RobZ
 
Posts: 1
Joined: Wed Jul 22, 2009 9:23 pm

Re: Project 2

Postby cezaridox on Thu Aug 20, 2009 4:06 pm

#include <iostream>

using namespace std;

int function1(int, int);
int function2(int, int);
int function3(int, int);
int function4(int, int);


int main()
{
int a=0,b=0;
char z,r;
bool n = true;

sus:


cout << "Input number A: ";
cin >> a;

cout << "Input number B: ";
cin >> b;


function4(a,b);

cout<<" To try one more time hit Y(YES) or NA(not asigned for NO): " ;
cin >> z;

if (z=='y')

n=true;

else

n=false;

if(n== false)
{
return 0;
}
else if (n == true)
{
cout << "Do you want to clear screen?: ";
cin >> r;
}

if ((r == 'y')&& (r='y'))
{
system ("cls");
goto sus;
}
else
goto sus;



return 0;
}

int function1(int a, int b)
{

cout<< a <<" = "<< b<<"\n" ;

if((a)%2)
{
cout<< a << " is odd.\n";
}
else
{
cout<< a <<" is even.\n";
}

{
cout<<" Difference between "<< a << " and " << b << " is " << a-b<<endl;
}




}

int function2(int a, int b)
{


cout<< a << " < " << b <<"\n";

if(b > a)
{
cout<< b << " > " << a <<"\n" ;
cout <<" They are not equal !!\n";
}
if(a < b)
{
cout<<" Difference between "<< b << " and " << a << " is " << (b - a) <<endl;
}
else
{
cout<<" Difference between "<< a << " and " << b << " is " << (a - b) <<endl;
}

if((a)%2)
{
cout<< a <<" is odd.\n" ;
}
else
{
cout<< a <<" is even.\n";
}

if((b)%2)
{
cout<< b <<" is odd.\n" ;
}
else
{
cout<< b <<" is even.\n";
}

}
int function3(int a, int b)
{

if(a > b)
{
cout << a << " > " << b <<"\n";
}
if(b < a)
{
cout << b << " < " << a <<"\n";
cout <<" They are not equal !! \n";
}

if(a > b)
{
cout<<" Difference between "<< a << " and " << b << " is " << (a - b) <<endl;
}
else
{
cout<<" Difference between "<< b << " and " << a << " is " << (b - a) <<endl;
}

if((a)%2)
{
cout<< a <<" is odd.\n" ;
}
else
{
cout<< a <<" is even.\n";
}

if((b)%2)
{
cout<< b <<" is odd.\n" ;
}
else
{
cout<< b <<" is even.\n";
}



}
int function4(int a, int b)
{

if (a == b)
return function1(a,b);
else if (a < b)
return function2(a,b);
else
return function3(a,b);
}
cezaridox
 
Posts: 2
Joined: Tue Aug 18, 2009 11:15 am

Re: Project 2

Postby sawm on Mon Aug 31, 2009 12:33 pm

Heres mine i think i forgot something but i dono what xD anyways let me know if i did something wrong, thanks for these wonderful projects there awesome practice wen im outa ideas especially keep it up tho project 3 sounds alot maybe not HARDER but longer lol well let me know if you find something unpleasant and i know i should code in a little neater way :/ il end up getting the hang of that write xD peace !

-sawm <3-

Code: Select all
//program that tell you stats for 2 chosen numbers? :D
//by: Sawm
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
      do{
        char ExitE;
        bool exitN = true;



          system("TITLE SPORK POWER");
      system("COLOR 2");

int firstNumber, secondNumber;


    cout << "                     !!!welcome to analyse my numbers!!!\n\n\n\n\n\n\n\n\n\n                               Please wait...\n\n\n\n\n\n\n\n\n\n\n\n\nBy: Sawm" << endl;
    Sleep(3300);
    system("cls");
    cout << "\n\n\n\n\n\n\n\n\n                     The game is simple actualy...\n\n";
    Sleep(100);
    cout <<"                 First Number: ";
    cin>>firstNumber;
    cout <<"                Second Number: ";
    cin>>secondNumber;
system("COLOR c");
        //now the stats part! :D
        float firstFloat = firstNumber, secondFloat = secondNumber;

        cout<<"\n           _statistics_";
        if( firstNumber == secondNumber )
            {
               cout<<"\n\n -> "<< firstNumber <<" and "<< secondNumber << " are equal ";
               Sleep(2000);
                }
            else
               cout<<"\n\n -> "<< firstNumber <<" and "<< secondNumber << " are not equal ";
               Sleep(2000);

        if( firstNumber != secondNumber && firstNumber > secondNumber )
        {
            cout<<"\n -> "<< firstNumber <<" is Bigger then "<< secondNumber << " ";
            Sleep(2000);
            }
                if( firstNumber != secondNumber && firstNumber < secondNumber )
                {
                 cout<<"\n -> "<< secondNumber <<" is biger then "<< firstNumber << " ";
                    Sleep(2000);
                    }

        cout<<"\n -> "<< firstFloat <<" divided by "<< secondFloat << " equals " << firstFloat / secondFloat;
        Sleep(2000);
        cout<<"\n -> "<< secondFloat <<" divided by "<< firstFloat << " equals " << secondFloat / firstFloat ;
        Sleep(2000);
        cout<<"\n -> The diference betwen "<< firstNumber <<" and "<< secondNumber <<" is "<< firstNumber - secondNumber ;
        Sleep(2000);
        if( (firstNumber % 2) == 0)
        {
            cout<<"\n -> "<< firstNumber << " is even";
            Sleep(2000);
            }
            else
            cout<<"\n -> "<< firstNumber << " is odd";
            Sleep(2000);


                    if( (secondNumber % 2) == 0)
            {
            cout<<"\n -> "<< secondNumber << " is even";
            Sleep(2000);
            }
            else
            cout<<"\n -> "<< secondNumber << " is odd";
            Sleep(2000);

    cout<<"\n\n                                         That was easy wana try again?(y/n); ";
    cin>>ExitE;

    if( ExitE != 'y' )
        {
         system("cls");
        cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n                                GOOD BYE!!!\n\n\n\n\n\n";
        Sleep(2000);
            return 0;
        }
        else;
}while(true);

}
sawm
 
Posts: 8
Joined: Fri Aug 28, 2009 3:24 pm

Re: Project 2

Postby liquid on Sat Sep 05, 2009 4:27 am

My try. I think it does all it has to do and should be fairly fail state-proof, but I still haven't thoroughly checked it out. Had some very useful help too when it came down to the function and the division by zero adjustments, otherwise it worked but it could be "broken" fairly easy. I was somewhat on the right course but it seemed like a nice explanation and some syntax fixes made all the difference :D
All comments/remarks/criticism/suggestions are welcome. No 'goto' this time :d
Does it matter in resource consumption/time to execute if I put
int a = int1 - int2;
int a1 = int2 - int1;
within the if-block so it doesn't "live" outside in the main function?

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

using namespace std;

void GetIntFromInput(int& i)
   {
      while ((cout << " ") && !(cin >> i))
      {
         cout << "This is not an integer, try again:";
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(), '\n');
      }
      cin.ignore(numeric_limits<streamsize>::max(), '\n');
   }

int main()
{
   int int1 = 0;
   cout << "Enter an integer:";
   GetIntFromInput(int1);
   int int2 = 0;
   cout << "Enter a second integer:";
   GetIntFromInput(int2);


   if (int1 == int2)
      cout << "\n" << int1 << " is equal to " << int2 << ".\n";
   if (int1 < int2)
      cout << int1 << " is not greater than " << int2 << ".\n";
   if (int1 > int2)
      cout << int1 << " is greater than " << int2 << ".\n";

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

   if (int1< 0)
      cout << int1 << " is a negative number.\n";
   if (int2<0)
      cout << int2 << " is a negative number.\n";
   
   int a = int1 - int2;
   int a1 = int2 - int1;
   if (int1 > int2)
      cout << "The difference between the two numbers is " << a << ".\n";
   if (int1 < int2)
      cout << "The difference between the two numbers is " << a1 << ".\n";

   
   if (int2==0)
      cout << "Cannot divide by zero.\n";
   else
      cout << int1 << " / " << int2 << " = " << double(int1)/double(int2) << "\n";
   if (int1==0)
      cout << "Cannot divide by zero.\n";
   else
      cout << int2 << " / " << int1 << " = " << double(int2)/double(int1) << "\n";
   
   system("pause");
   return 0;
}
liquid
 
Posts: 3
Joined: Wed Sep 02, 2009 7:36 am

Re: Project 2

Postby noobgrammer on Sat Sep 05, 2009 7:40 am

Your program works fine for me

You wanted a comments in this program
It doesn't really matter in this program but when you have a set of if statements use else ifs after first if. with all ifs it will still check each if even if it had already found one true.

I commented this out on mine #include <stdlib.h> and it still worked fine. I'm no professional so I couldn't tell you if you needed it on yours or not

on your function question to my understanding you want to use functions as much as possible (without getting carried away) for that it should be fine

The only thing I noticed is if I type a float it just cuts off the decimal the error check doesn't catch that.
If anybody knows how to fix that I would like to know too
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 193
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Project 2

Postby Fatrabit on Wed Sep 23, 2009 8:07 pm

Here is mine, I left out if its less than or equal to. Thanks noobgramer works great.

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

using namespace std;

int main()
{
   float a;
   float b;

   cout << "Welcome to Interger Statistics!\nPlease enter your two integers now.\n";
   
   cin >> a;
   cin >> b;
   
   cout <<endl << "Here are your statistics:\n";

   if(a==b)
   {
      cout << "The integers are equal.\n";
   }

   else if (a>b)
   {
      cout << a <<" is greater than " << b << ".\n";
   }

   else if (a<b)
   {
      cout << a <<" is lesser than " << b << ".\n";
   }

   if (a >= b)
   {
      cout << a <<" is greater than or equals to " << b << endl;
   }
   
   else   if (b >=! a)
   {
      cout << b <<" is not greater than or equals to " << a << endl;
   }

   if (a <= -1)
   {
      cout << a << " is a negative integer.\n";
   }

   else
   {
      cout << a << " is a positive integer.\n";
   }

   if (b <= -1)
   {
      cout << b << " is a negative integer.\n";
   }

   else
   {
      cout << b << " is a positive integer.\n";
   }

if((int)a % 2 == 0)
   {
      cout << a <<" is even.\n";
   }

   else cout <<a <<" is odd.\n";

   if((int)b % 2 == 0)
   {
      cout << b <<" is even.\n";
   }

   else cout <<b <<" is odd.\n";
   

   cout << a << " + " << b << " = " << (a+b) <<endl;
   cout << a << " - " << b << " = " << (a-b) <<endl;
   cout << a << " / " << b << " = " << (a/b) <<endl;
   cout << b << " / " << a << " = " << (b/a) <<endl;
   cout << a << " * " << b << " = " << (a*b) <<endl;

   string cont;
   
   cout << endl;
   cout << "Would you like to continue with Integer Statistics ('continue') or would you like to exit Integer Statistics? ('exit')\n";

   cin >> cont;

   if (cont == "continue")
   {
      main();
   }
   else
   {
      return 0;
   }
   
}
Last edited by Fatrabit on Thu Sep 24, 2009 5:12 pm, edited 2 times in total.
Fatrabit
 
Posts: 11
Joined: Sun Sep 20, 2009 10:04 pm

Re: Project 2

Postby noobgrammer on Wed Sep 23, 2009 11:05 pm

You could do this as a example

Code: Select all
int main()
{

   double number = 10.5;//or float

   if ((int)number % 2 == 0)
   {
      //code here;
   }

}


this will temperately make it a int its called typecasting I believe
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 193
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Project 2

Postby darmstrong on Sun Oct 11, 2009 12:08 am

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

using namespace std;

int main ()
{
int a;
int b;

cout << "Welcome to Dan's Number Compairer Program!" << endl;
cout << "(C) Armstrong Dynamics, Inc. (C) 2009 - 2010" << endl;
cout << "(TM) Armstrong Dynamics, Inc." << endl << endl << endl << endl;

cout << "Enter your first integer... ";
cin >> a;
cout << endl;

cout << "Enter your second integer... ";
cin >> b;
cout << endl << endl << "RESULTS:" << endl << endl << endl;

if ( a == b )
{
cout << a << " " << "is equil to" << " " << b << endl << endl;
cout << a << " " << "is NOT greater than" << " " << b << endl;
cout << a << " " << "is NOT less than" << " " << b << endl;
cout << b << " " << "is NOT greater than" << " " << a << endl;
cout << b << " " << "is NOT less than" << " " << a << endl;
}
else
{
if ( (a != b) && (a < b) )
{
cout << a << " " << "is NOT equil to" << " " << b << endl << endl;
cout << a << " " << "is NOT greater than" << " " << b << endl;
cout << a << " " << "is less than" << " " << b << endl;
cout << b << " " << "is greater than" << " " << a << endl;
cout << b << " " << "is NOT less than" << " " << a << endl;
}
else
{
if ( (a != b) && (a > b) )
{
cout << a << " " << "is NOT equil to" << " " << b << endl << endl;
cout << a << " " << "is greater than" << " " << b << endl;
cout << a << " " << "is NOT less than" << " " << b << endl;
cout << b << " " << "is NOT greater than" << " " << a << endl;
cout << b << " " << "is less than" << " " << a << endl;
}
else
{
cout << "FATAL ERROR...";
}
}
}

int f;
cin >> f;
return 0;
}
darmstrong
 
Posts: 2
Joined: Sat Oct 10, 2009 7:48 pm

Re: Project 2

Postby noobgrammer on Mon Oct 12, 2009 11:26 am

Here darmstrong I changed it a little to show you a little cleaner way of using the if's
I also showed you a way to use" \n"; instead of <<endl; I believe the endl is a little slower to use but of course for this kind of stuff that is pointless, I just am showing you a faster way. The endl clears the buffer out I think I'm not sure exactly how it works

and try to use the code tags it makes it cleaner looking and easier to copy heres a link
practice-code-posting-rules-t10.html
if you're not sure how

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


int main ()
{
   using std::cout;
   using std::cin;
   using std::endl;

   int a;
   int b;

   cout << "Welcome to Dan's Number Compairer Program!\n";
   cout << "(C) Armstrong Dynamics, Inc. (C) 2009 - 2010\n";
   cout << "(TM) Armstrong Dynamics, Inc.\n\n\n";

   cout << "Enter your first integer... ";
   cin >> a;
   

   cout << "\nEnter your second integer... ";
   cin >> b;
   cout <<  "\n\nRESULTS:\n\n\n" ;

   if ( a == b )
   {
      cout << a << " " << "is equil to" << " " << b << "\n\n";
      cout << a << " " << "is NOT greater than" << " " << b << "\n";
      cout << a << " " << "is NOT less than" << " " << b << "\n";
      cout << b << " " << "is NOT greater than" << " " << a << "\n";
      cout << b << " " << "is NOT less than" << " " << a << "\n";
   }
   
   
   else if ( (a != b) && (a < b) )
   {
      cout << a << " " << "is NOT equil to" << " " << b << endl << endl;
      cout << a << " " << "is NOT greater than" << " " << b << endl;
      cout << a << " " << "is less than" << " " << b << endl;
      cout << b << " " << "is greater than" << " " << a << endl;
      cout << b << " " << "is NOT less than" << " " << a << endl;
   }
   
   else if ( (a != b) && (a > b) )
   {
   cout << a << " " << "is NOT equil to" << " " << b << endl << endl;
   cout << a << " " << "is greater than" << " " << b << endl;
   cout << a << " " << "is NOT less than" << " " << b << endl;
   cout << b << " " << "is NOT greater than" << " " << a << endl;
   cout << b << " " << "is less than" << " " << a << endl;
   }
   else
   {
   cout << "FATAL ERROR...";
   }
   

   int f;
   cin >> f;
   return 0;
}
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 193
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Project 2

Postby jwright on Wed Oct 21, 2009 2:08 pm

If you want an efficient way of doing this then skip this one!. But hey it seems to work.
I had to skip the positive or negative part because i dont yet know how to test for them.
Plus in the final operation you will find remainders instead of the value listed as a decimal, again because I wasn't paying attention when it was covered in the vid, or it has been forgotten.



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

int main()
{
   int firstNumber;

   int secondNumber;

   cout << "Please enter an integer number:";
   cin >> firstNumber;
   cout << "\nPlease enter another integer number:";
   cin >> secondNumber;

   //Whether they are equal.
   //If not equal, Which number is greater than the other.

   if (firstNumber==secondNumber)
      cout << firstNumber << "and" << secondNumber << " are equal!\n";
   else
      if (firstNumber>secondNumber)
         cout << firstNumber << "is greater than" << secondNumber << endl;
      else
         cout << secondNumber << "is greater than" << firstNumber << endl;

   //If not equal Which number is less than the other (duh!)

   if (firstNumber!=secondNumber)
      if (firstNumber<secondNumber)
         cout << firstNumber << "is lesser than" << secondNumber << endl;
      else
         cout << secondNumber << "is lesser than" << firstNumber << endl;

   //(even if equal) Whether the first number is greater or equals to the second, and vice versa.

   if (firstNumber>=secondNumber)
      cout << firstNumber << "is greater than or equals to" << secondNumber << endl;
   else
      cout << firstNumber << "is not greater than or equals to" << secondNumber << endl;

   if (firstNumber!=secondNumber)
      if (secondNumber>=firstNumber)
         cout << secondNumber << "is greater than or equals to" << firstNumber << endl;
      else
         cout << secondNumber << "is not greater than or equals to" << firstNumber << endl;


   //Whether the first number is less or equals to the second, and vice versa (duh!)

   if (firstNumber<=secondNumber)
      cout << firstNumber << "is lesser than or equals to" << secondNumber << endl;
   else
      cout << firstNumber << "is not lesser than or equals to" << secondNumber << endl;

   if (firstNumber!=secondNumber)
      if (secondNumber<=firstNumber)
         cout << secondNumber << "is lesser than or equals to" << firstNumber << endl;
      else
         cout << secondNumber << "is not lesser than or equals to" << firstNumber << endl;

   //Whether the numbers are even or odd

   if (firstNumber%2==0)
      cout << firstNumber << "is even" << endl;
   else
      cout << firstNumber << "is odd" << endl;

   if (secondNumber%2==0)
      cout << secondNumber << "is even" << endl;
   else
      cout << secondNumber << "is odd" << endl;

   //Whether the numbers are positive or negative
   //Unsure with this one, should revise vids.


   //The difference between the two numbers

   if (firstNumber>secondNumber)
      cout << "The difference between the two numbers is:" << firstNumber-secondNumber << endl;
   else
      if (firstNumber<secondNumber)
         cout << "The difference between the two numbers is:" << secondNumber-firstNumber << endl;
      else
         cout << "The difference between the two numbers is:0" << endl;

   //The result of the first number divided by the other, and vice versa. In case the result has a fractional part, print the fractional part as well.
   //Can't remember how to get decimal places. Will revise vids. Improvise with remainders for now...

   cout << firstNumber << '/' << secondNumber << '=' << firstNumber/secondNumber << "remainder" << firstNumber%secondNumber << endl;
   cout << secondNumber << '/' << firstNumber << '=' << secondNumber/firstNumber << "remainder" << secondNumber%firstNumber << endl;

   char f;
   cin >> f;
   return 0;
}
jwright
 
Posts: 7
Joined: Wed Oct 21, 2009 11:47 am
Location: Essex, England

Re: Project 2

Postby noobgrammer on Wed Oct 21, 2009 4:02 pm

To tell if a number is positive or negative you would just do this

Code: Select all
if (number > 0)
std::cout<< "positive\n";
else
std::cout<< "negative\n";


to have it show decimal you would have to use float or double instead of int

Code: Select all
int number; //will only show whole numbers

float number; //will show whole and decimal

double number; //will give you whole number and decimal and will handle a number bigger than you could count
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 193
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Project 2

Postby jwright on Wed Oct 21, 2009 4:10 pm

Whoa cant beleive I didn't think of

if (number>0)

I feel pretty daft now....and I suppose I knew float, just forgot it :S.

Anyways thanks a lot :)
jwright
 
Posts: 7
Joined: Wed Oct 21, 2009 11:47 am
Location: Essex, England

Re: Project 2

Postby iceman on Fri Nov 20, 2009 7:36 am

Well i finished project two as well as project one and it's time for the big momma, the third project, it will be harder than the rest, but i am confident :)

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

void main()
{
   int int1 = 0;
   int int2 = 0;
   bool bquit = true;
   char cterminator;

   while(bquit == true)
   {
      cout << "Welcome to the number stats app!" << endl;
      cout << "This program has been coded by: Iceman" << endl << endl;

      cout << "please enter first integer:";
      cin >> int1;

      cout << "please enter second integer:";
      cin >> int2;

      //check which integer is greater, if not equal
      if(int1 > int2)
      {
         cout << int1 << " is greater than " << int2 << "!" << endl;
      }

      else if(int1 < int2)
      {
         cout << int1 << " is less than " << int2 << "!" << endl;
      }

      else if(int1 == int2)
      {
         cout << int1 << " is equal to " << int2 << "!" << endl;
      }

   //check if integers are even or odd
      if((int1 % 2) == 0)
      {
         cout << int1 << " is an even number!" << endl;
      }
      else
      {
         cout << int1 << " is an odd number!" << endl;
      }

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

      //check if integers are possitive or negative
      if(int1 < 0)
      {
         cout << int1 << " is a negative number!" << endl;
      }
      else
      {
         cout << int1 << " is a positive number!" << endl;
      }

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

      //the difference between the two numbers
      cout << "the difference between " << int2 << " and " << int1 << " is " << int2-int1 << "!" << endl;

      //divide both numbers
      int result = int1/int2;
      cout << int1 << "/" << int2 << " = " << result << "!" << endl;

      int result2 = int2/int1;
      cout << int2 << "/" << int1 << " = " << result2 << "!" << endl;

      cout << "would you like to continue?(y/n)";
      cin >> cterminator;
      if(cterminator == 'y' || cterminator == 'Y')
      {
         bquit = true;
      }
      else
      {
         bquit = false;
      }
   }
}   
iceman
 
Posts: 6
Joined: Fri Nov 20, 2009 3:58 am

Re: Project 2

Postby Rodband on Sun Nov 22, 2009 10:56 pm

Here's mine, has some random stuff in it for fun but yea this is it

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

using namespace std;

int main()
{
   int firstnumber;
   int secondnumber;

   cout << "Welcome to the number statistics machine!\n\n";
   cout << " 00  00 0000 00  00 " << endl;
   cout << "  0000  0  0  0000  " << endl;
   cout << "   00   0000   00   " << endl;
   cout << "   00   0  0   00   " << endl;
   cout << "   00   0  0   00   " << endl;
   cout << "\nEnter a number: ";
   cin >> firstnumber;
   cout << endl;
   
   cout << "Enter another number: ";
   cin >> secondnumber;
   cout << endl;

   if (firstnumber == secondnumber )  //Test equality
      cout << "The numbers are equal!";
   else
      if ( firstnumber > secondnumber ) //Greater than
         cout << "The numbers are not equal and "<< firstnumber << " is greater than " << secondnumber;
      else
         if ( firstnumber < secondnumber ) //less than
            cout << "The numbers are not equal and "<< firstnumber << " is less than " << secondnumber;

   if ( firstnumber % 2 == 0 ) //first number even or odd
      cout << "\nThe first number is even!\n";
   else
      cout << "\nThe first number is odd!\n";
   
   if ( secondnumber % 2 ==0 ) //second number even or odd
      cout << "The second number is even!\n";
   else
      cout << "The second number is odd!\n";

   if ( firstnumber > 0 ) //first number poss or neg
      cout << "The first number is positive!\n";
   else
      cout << "The first number is negative!\n";

   if ( secondnumber > 0 ) //second number poss or neg
      cout << "The second number is positive!\n";
   else
      cout << "The second number is negative!\n";

   cout << "\nHere is some more infornation\n\n";
      // difference between numbers
   cout << "The difference between " << firstnumber << " and " << secondnumber << " is " << firstnumber - secondnumber << endl;
      //first divided by second
   cout << firstnumber << " divided by " << secondnumber << " equals " << firstnumber / secondnumber << " with a remainder of " << firstnumber % secondnumber << endl;
      //second divided by first
   cout << "And " << secondnumber << " divided by " << firstnumber << " equals " << secondnumber / firstnumber << " with a remainder of " << secondnumber % firstnumber << endl;

   cout << "\nType anything and press enter to exit\n";

   char f;
   cin >> f;
   return 0 ;
}
Rodband
 
Posts: 1
Joined: Sat Nov 21, 2009 7:58 pm

PreviousNext

Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests