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.

Project 2

Postby antiRTFM on Tue Apr 15, 2008 7:39 pm

Welcome back! Lets do some more!

This project will be about number statistics. An integer number or two is given, and statistics about the numbers are printed.

Here is what happens:

1: Ask user to enter an integer number
2: Ask user to enter another integer number
3: Print out statistics (see below)
4: Ask user to enter some stuff to exit program.

The following statistics should be printed about the 2 given numbers;

- Whether they are equal.
- If not equal, Which number is greater than the other. Example:

76 is greater than 34

- If not equal Which number is less than the other (duh!)
- (even if equal) Whether the first number is greater or equals to the second, and vice versa. Example:

76 is not greater-or-equals to 34
34 is not greater-or-equals to 76

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

- Whether the numbers are even or odd
Example:
76 is even
34 is even

- Whether the numbers are positive or negative
- The difference between the two numbers
- 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.

Good luck!
Last edited by antiRTFM on Tue Apr 22, 2008 1:28 am, edited 1 time in total.
User avatar
antiRTFM
Administrator
 
Posts: 467
Joined: Sun Apr 13, 2008 9:10 am

Postby Danielghofrani on Tue Apr 15, 2008 10:47 pm

Code: Select all

#include "stdafx.h"
#include <iostream>
using namespace std ;
int main ()
{

   
   
   int firstnumber ;
   int secondnumber ;
   cout << " please enter the first number " << endl ;
    cin>> firstnumber ;
   
   cout << " please enter the second number " << endl ;
   cin >> secondnumber ;
   
   
   if (firstnumber==secondnumber){cout<< " the two numbers are equal"<< endl ; }

      if (firstnumber>secondnumber){
         
         cout << firstnumber << " is bigger than " << secondnumber<< endl ;
          cout << " and " << secondnumber << " is smaller than " << firstnumber<< endl ;}
      
      

       if (firstnumber<secondnumber){cout << secondnumber << " is bigger than " << firstnumber<< endl ;
                                     cout <<"and" << firstnumber << " is smaller than " << secondnumber<< endl ; }
   
                         
                         
                             if (firstnumber >= secondnumber){cout<< firstnumber<< " is greater or equal to " << secondnumber<<endl;
                             cout << "  and also "<< secondnumber << " is smaller or equal to " << firstnumber << endl;                               
                             cout << " and the difference between the numbers is "<< firstnumber-secondnumber << endl; }
                            
                             else if (firstnumber <= secondnumber){cout<< secondnumber<< " is greater or equal to " << firstnumber<<endl;
                                                                     cout<< " and " << firstnumber << " is smaller or equal to " << secondnumber<<endl;       
                                                                   cout << " and the difference between the numbers is "<< secondnumber-firstnumber << endl; }


     
                            
                            
                            
                     
                     



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

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


                             if(firstnumber>0){cout<< firstnumber << " is positive " << endl;}
                             else {cout << firstnumber<< " is negative "<< endl;}
                            
                             if(secondnumber>0){cout<< secondnumber << " is positive " << endl;}
                             else {cout << secondnumber<< " is negative "<< endl;}

                            




                     


                            
   char f ;
   cin >> f ;
   return 0 ;
}
Last edited by Danielghofrani on Wed Apr 16, 2008 5:33 pm, edited 1 time in total.
Danielghofrani
 
Posts: 3
Joined: Tue Apr 15, 2008 8:54 pm

Postby antiRTFM on Wed Apr 16, 2008 2:05 am

Danielghofrani:

Had to work a bit on spacing things out so i can read clearly...

Some corrections are;

- extra semicolons after if/else statements' closing brace. I may not have mentioned it in the videos, but when a statement uses opening/closing braces, it removes the need of finishing off the statement with a semicolon.

- You forgot to use '<<' again between the variables and the text in 2 'cout' commands. Every separate item that will be printed out with 'cout' must have its own set of preceding '<<'.

- Several more statistics are missing. Scroll up to the project description and see.

Otherwise good job!

When you are done fixing it up you can post your code again.
Last edited by antiRTFM on Tue Aug 19, 2008 3:56 pm, edited 1 time in total.
User avatar
antiRTFM
Administrator
 
Posts: 467
Joined: Sun Apr 13, 2008 9:10 am

Postby antiRTFM on Thu Apr 17, 2008 6:14 pm

Hm... ill have to make some rules about editing previous posts to make it clearer for readers who come in later... maybe something like every time you edit a post you should add "edited" to the subject.

Anyway, almost perfect. The last statistic is still missing, the result of dividing one by the other.
User avatar
antiRTFM
Administrator
 
Posts: 467
Joined: Sun Apr 13, 2008 9:10 am

Postby Iacoopa on Sat May 24, 2008 3:37 pm

I did all of the objectives EXCEPT telling if the number is even or odd (I dont know how to do that necessarily) So here is my code.

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

using namespace std;

int main()
{
   float a;
   float b;

   cout <<"Type in two Integers, And I will tell you a few facts about them.";
   cout <<"\nEnter your first number: ";
   cin >> a;
   cout <<"\nEnter your second number: ";
   cin >> b;
   cout << "Statistics: \n";
   if (a > 0)
   {
      cout << a <<" is positive\n";
   }
   else
   {
      cout << a <<" is negative\n";
   }
   if (b > 0)
   {
      cout << b <<" is positive.\n";
   }
   else
   {
      cout << b <<" is negative\n";
   }
   if (b == a)
   {
      cout << a <<" is equal to " << b;
   }
   if ( a < b )
   {
      cout << a <<" is less than " << b;
   }
   if ( a > b )
   {
      cout << a <<" is greater than " << b;
   }

   cout <<"\nThe difference between "<< a << " and " << b << " is " << a - b <<endl;
   cout << a << " divided by " << b << " equals " << a / b <<endl;
   cout << b << " divided by " << a << " equals " << b / a <<endl;
   
   char f;
   cin >> f;
   return 0;
}


By the way I might be able to host an Index for this site with the link to this forum and the link to the download of C++ with some of your videos. If you're interested.
Iacoopa
 
Posts: 7
Joined: Thu May 22, 2008 7:18 pm
Location: Mars

Postby C++ on Sun May 25, 2008 8:02 am

Code: Select all
//*******************************
//****** Number Statistics ******
//******     Version 1     ******
//*******************************

#include <conio.h>
#include <sstream>
#include <iostream>
using namespace std;

int main(int argc, char *args[])
{
   int number1, number2;
   char c;
   bool cmdline = true;
   if (argc >= 3)
   {
      stringstream s1(args[1]);
      stringstream s2(args[2]);
      s1 >> number1;
      s2 >> number2;
   }
   else
      cmdline = false;
   do
   {
      system("cls");
      if (!cmdline)
      {
         cout << "Please enter the first number: ";
         cin >> number1;
         cout << "Please enter the second number: ";
         cin >> number2;
      }
      else
         cmdline = false;

      if (number1 > number2)
         cout << "Number 1 (" << number1 << ") is greater than number 2 (" << number2 << ")"<< endl;
      else if (number1 < number2)
         cout << "Number 1 (" << number1 << ") is smaller than number 2 (" << number2 << ")" << endl;
      else
         cout << "Number 1 (" << number1 << ") and number 2 (" << number2 << ") are equal to each other." << endl;

      if ((number1 % 2) == 0)
         cout << "Number 1 (" << number1 << ") is even." << endl;
      else
         cout << "Number 1 (" << number1 << ") is odd." << endl;

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

      if (number1 < 0)
         cout << "Number 1 (" << number1 << ") is negative." << endl;

      if (number2 < 0)
         cout << "Number 2 (" << number2 << ") is negative." << endl;

      if (number1 > number2)
      {
         cout << "The difference between number 1 (" << number1 << ") and number 2 (" << number2 << ") is " << number1 - number2 << endl;
         cout << "Number 1 (" << number1 << ") divided by number 2 (" << number2 << ") is " << number1 / number2 << endl;
      }
      else
      {
         cout << "The difference between number 1 (" << number1 << ") and number 2 (" << number2 << ") is " << number2 - number1 << endl;
         cout << "Number 2 (" << number2 << ") divided by number 1 (" << number1 << ") is " << number2 / number1 << endl;
      }

      cout << "Again? (y/n) ";
      do c = _getch(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n');
      cout << endl;
   } while(c != 'N' && c != 'n');
   return 0;
}


I know you haven't mentioned program arguments and stringstreams yet in your tuts, but I looked that up myself. I needed a way to convert strings to ints. Just in case someone needs a quick statistical view of a few numbers without having to prompt for numbers.
C++
teh awesome
 
Posts: 217
Joined: Sun May 25, 2008 7:45 am

Postby -S-S- on Tue Aug 19, 2008 2:16 pm

heres mine.. tried to keep it as simple as I could.

:D Mooving onto project three which hopefully should take a wee longer than 10 mins :D

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

int main (){
      system("TITLE Project 2");
      system("COLOR 4");
      int iNum1;
      int iNum2;
      char exit;
      bool bExit = true;
while(bExit == true){
      cout << " Please enter an interger number " <<endl;
      cin >> iNum1;
      cout << " Please enter a second integer number " <<endl;
      cin >> iNum2;
     
      if (iNum1 == iNum2) {
                cout << iNum1 << " is " << " equal to " << iNum2 <<endl;
                 }
      if (iNum1 < iNum2) {
                cout << iNum1 << " is less than" <<  iNum2 <<endl;
                 }
      if (iNum1 > iNum2) {
                cout << iNum1 << " is greater than " << endl <<endl;               
                }
      if (iNum1 <= iNum2) {
                cout << iNum1 << " is less than or equal to " << iNum2 <<endl;                           
                }
      if (iNum1 >= iNum2) {
                cout << iNum1 << " is greater than or equal to " << iNum2 <<endl;
                 }
      if ((iNum1 % 2) ==0 ){
                 cout << iNum1 << " is an even number " << endl;
                 } else { cout << iNum1 << "is a negative number " << endl;
                         }
      if ((iNum2 % 2) == 0 ) {
                 cout << iNum2 << " is an even number " <<endl;
                 } else {
                        cout << iNum2 << " is an odd number " << endl << endl;
                        } 
      cout << " The difference between " << iNum1 << " and " << iNum2 << " is " << iNum1-iNum2 << endl;
      cout << iNum1 << " divided by " << iNum2 << " is " << iNum1/iNum2 << endl <<endl;
      cout << iNum2 << " divided by " << iNum1 << " is " << iNum2/iNum1 << endl <<endl;       
      cout << " To Continue press y " << endl;
      cin >> exit;
      if (exit ==  'y' ) {
               bExit = true;
               } else {
                      bExit = false;
                      }
   
                     
                           
       
        }//while
       
      return 0;
     
      }
-S-S-
 
Posts: 13
Joined: Sat Aug 16, 2008 2:57 pm

Postby Marss++ on Wed Aug 20, 2008 10:39 am

Ok... There are a few things that you could work on with your code.



First of all the basics: Here is what I got when I typed in 2 and 6.

Exact Copy:

___________________________________

2 is less than6
2 is less than or equal to 6
2 is an even number
6 is an even number
The difference between 2 and 6 is -4.
2 divided by 6 is 0

6 divided by 2 is 3

To Continue press y

____________________________________

Line (1) 2 is less than6
space the six out


Line (2) 2 is less than or equal to 6
we don't need to know this since the first line
just told us that it was less than, and it's not
equal too.


Line(3) 2 is an even number
Good


Line(4) 6 is an even number
Good


Line(5) The difference between 2 and 6 is -4.
Here's a little piece of code that will fix that problem:

Code: Select all
if (number < 0)
{
   number *= -1;
}



Line(6) 2 divided by 6 is 0
This is wrong, but because you used int
it comes out this way. Try using double,
that way it will come out with a decimal number.
Or because the assignment was to make it with
integers, you could check to see which one was bigger,
whatever one ended up to be bigger then that one
was the one that would the base of the division.


Line(6)6 divided by 2 is 3
This is good


Line(10) To Continue press y
Good

______________________________________________________


That was the machanics behind your code.


The next thing I want to talk about is why does it look the way it
does in the compiler. This may seem stupid to talk about but it is key
if your ever going to work on a project with multiple people
or even share your code with others like your doing now.

When you are typing in the compiler you will notice that it does many things for you. The main things are it indents lines and it colors words. There are a few purposes to this but the main thing is for organization.
After every opening bracket the next line gets indented another
few spaces. This is to show you bits of code. You should have all
your brackets end up so that the return statement is right at the end where it is suppose to be. If you look at your code. It's way out there.
So even though your code runs, when people look at it, it will take them
twice as long to figure out where things are, and whats happening because they're used to the standard way of indenting lines which you seemed to ignore here. I fixed up the code, just the orginization part. I want you and others to see how much it helped from the last code you posted.


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

int main ()
{
   system("TITLE Project 2");
   system("COLOR 4");
   int iNum1;
   int iNum2;
   char exit;
   bool bExit = true;
   while(bExit == true)
   {
      cout << " Please enter an interger number " <<endl;
      cin >> iNum1;
      cout << " Please enter a second integer number " <<endl;
      cin >> iNum2;
      if (iNum1 == iNum2)
      {
         cout << iNum1 << " is " << " equal to " << iNum2 <<endl;
      }
      if (iNum1 < iNum2)
      {
         cout << iNum1 << " is less than" <<  iNum2 <<endl;
      }
      if (iNum1 > iNum2)
      {
         cout << iNum1 << " is greater than " << endl <<endl;               
      }
      if (iNum1 <= iNum2)
      {
         cout << iNum1 << " is less than or equal to " << iNum2 <<endl;                           
      }
      if (iNum1 >= iNum2)
      {
         cout << iNum1 << " is greater than or equal to " << iNum2 <<endl;
      }
      if ((iNum1 % 2) ==0 )
      {
         cout << iNum1 << " is an even number " << endl;
      }
      else
      {
         cout << iNum1 << "is a negative number " << endl;
      }
      if ((iNum2 % 2) == 0 )
      {
         cout << iNum2 << " is an even number " <<endl;
      }
      else
      {
         cout << iNum2 << " is an odd number " << endl << endl;
      } 
      cout << " The difference between " << iNum1 << " and " << iNum2 << " is " << iNum1-iNum2 << endl;
      cout << iNum1 << " divided by " << iNum2 << " is " << iNum1/iNum2 << endl <<endl;
      cout << iNum2 << " divided by " << iNum1 << " is " << iNum2/iNum1 << endl <<endl;       
      cout << " To Continue press y " << endl;
      cin >> exit;
      if (exit ==  'y' )
      {
         bExit = true;
      }
      else
      {
         bExit = false;
      }
   }//while
   return 0;
}




I am in no way ripping on you. This was an excellent attempt to build an
integer statistic application. Great Job, your code just needed a few little things. Other then that. You did Great! :)
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 Doctor Salt on Wed Aug 20, 2008 11:49 am

I always check over the "formating" after I do the bulk of the programming... On my lil calculator project, I checked over everything to make sure it looks good too, which may be a bit time consuming, but definitely worth it.
I'm a 15 year old kid who has his heart set on Programming, almost as much as Marss++.......

Came here hoping to ask more questions so if you have any free time just say!
Doctor Salt
 
Posts: 147
Joined: Wed Jul 30, 2008 3:32 pm

Postby Marss++ on Wed Aug 20, 2008 1:57 pm

It is so worth it Salt.
It helps others help you.
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 Doctor Salt on Wed Aug 20, 2008 3:01 pm

Definitely. Well, for me, theres too parts to this.

1)Making the code all neat, and spaced out, and commented correctly.

2)What the user sees, all the text formating, etc.

I usually do part one WHILE i'm coding, because thats how I code it. It's too integral to do later. You could do part 2 afterwards, like spacing out things, adding in more "\n" at the end or beginning of sentences, etc.

Both are hugely important :P
I'm a 15 year old kid who has his heart set on Programming, almost as much as Marss++.......

Came here hoping to ask more questions so if you have any free time just say!
Doctor Salt
 
Posts: 147
Joined: Wed Jul 30, 2008 3:32 pm

Postby Marss++ on Wed Aug 20, 2008 3:29 pm

Right. Alot of times you want to get the brunt of the program down, then make it pretty.
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 antiRTFM on Wed Aug 20, 2008 4:21 pm

As the famous C++ Rule #1 goes;

Rule #1: Make it work, then fix it up.

Actually that is usually said about optimization. However code readability may be just as important as making it work, so that somone else can easily find problems/bugs etc, vital to "making it work".
User avatar
antiRTFM
Administrator
 
Posts: 467
Joined: Sun Apr 13, 2008 9:10 am

Postby Strazku on Mon Aug 25, 2008 11:22 pm

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

using namespace std;

int main()
{
   int a;
   int b;

   cout << "Hello and welcome to this program.  This program is designed to give you a few statistics about the intergers you decide to choose.\nPlease choose an interger: ";
   cin >> a;
   cout << "Thank you, please choose another interger: ";
   cin >> b;
   cout << "Thank you, here are your results." << endl << endl << endl;

   if (a == b)
      cout << a << " is equal to " << b << endl;
   else
      cout << a << " and " << b << " are not equal." << endl;
   if (a > b)
      cout << a << " is greater than " << b << endl;
   else
      cout << b << " is greater than " << a << endl;

   if (a < b)
      cout << a << " is less than " << b << endl;
   else
      cout << b << " is less than " << a <<endl;
   
   if((a % 2) == 0)
      cout << a << " is an even number " << endl;
   else
      cout << a << " is an odd number " << endl;
   if ((b%2)==0)
      cout << b << " is an even number" << endl;
   else
      cout << b << " is an odd number"  << endl;
   if (a >= b)
      cout << a << " is greater than or equal to " << b << endl;
   else
      cout << b << " is greater than or equal to " << b << endl;
   if (a <= b)
      cout << a << " is less than or equal to " << b << endl;
   else
      cout << b << " is less than or equal to " << a << endl;
   if(a > 0)
      cout << a << " is a possitive number" << endl;
   else
      cout << a << " is a negative number"  << endl;
   if(b > 0)
      cout << b << " is a possitive number" << endl;
   else
      cout << b << " is a negative number"  << endl;

   cout << "The difference between " << a << " and " << b << " are " << a-b << endl;
   cout << "The difference between " << b << " and " << a << " are " << b-a << endl;
   cout << b << " divided by " << a << " is " << b / a << endl;


   

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

Postby Marss++ on Tue Aug 26, 2008 2:10 am

A reply to strazku.
Please put into your editor so that you can see the colors and it's much easier to read. Thankyou.


Code: Select all
//Ok.. Here is the code I made for Strazku.
//Heavily Commented For learning purposes
//First things First, We include what we need to.
//So I'll include <iostream> so we can use the
//Cout and Cin Objects and other things in this code
#include <iostream>

//Now I will Begin the Program here. With main.
int main()
{
    //First things first, I will declare two integer
    //variables so that we can use them later.
    //I changed there name so that it would be easier to
    //Know what specific variable I'm using in my program.
    //Not that "a" and "b" aren't good. Just when you get
    //Really compilcated code and you have 100 differenet
    //Integer variables you are going to need to give them
    //Meaningfull names this way it's easy to identify them
    //In your code. I declare them on the same line seperating
    //Them by commas.
    int fNum, sNum;
   
    //Now I will Get the Introduction down. Simply by using the
    //cout object. But now I have to use the std:: prefix because
    //The compiler needs to know where to get the cout object.
    std::cout << "Hello, and Welcome to my Integer Statistic Program!" << std::endl;
    std::cout << "Please type in The Fist Integer: ";
   
    //After asking for the first integer We get it by using
    //std::cin >> fNum;
    std::cin >> fNum;
    std::cout << "Thankyou. Please Enter Second Number: ";
    //Then we ask for the second number and get it by using
    //std::cin >> sNum;
    std::cin >> sNum;
    std::cout << "--------------------------------------\n";
   
    //Now that we have the two numbers we can perform the meat of the
    //Program.
    //We'll start out with the first set of if statements
    if (fNum == sNum)
    {
             //I like using brackets when I know there are going to
             //be a lot of if statements.
             //That way it's real clear where everything is
             std::cout << "Both Numbers are equal!" << std::endl;
    }
    //Now I use Else if Because then it's like multiple else statements
    //But narrowed to only what is in the if statement.
    else if (fNum > sNum)
    {
         std::cout << "The First Number is Greater then The Second Number!" << std::endl;
    }
    //Another Else if Statement saying just the opposite of the last one
    else if (fNum < sNum)
    {
         std::cout << "The First Number is Less then The Second Number!" << std::endl;
    }
    std::cout << "--------------------------------------\n";
   
   
    //The second If statements will be to test if the numbers the user entered
    //In were even or odd.
    //These will take a few if and else if statements.
    //Also remember that "&&" is just like typing "AND"
   
    if ((fNum % 2 == 0) && (sNum % 2 == 0))
    {
              //If both the first number "AND" the second number
              //Can be evenly divided in half then do the
              //Following:
              std::cout << "Both numbers are Even!" << std::endl;
    }
    else if ((fNum % 2 == 0) && (sNum % 2 != 0))
    {
         //Or else if the first number can be divided evenly
         //"AND" the second number cannot do the following:
         std::cout << "The first number is even," << std::endl;
         std::cout << "but the second number is odd." << std::endl;
    }
    else if ((fNum % 2 != 0) && (sNum % 2 == 0))
    {
         //Or else if the first number cannot be divided evenly
         //"AND the second number can do the following:
         std::cout << "The First number is odd," << std::endl;
         std::cout << "but the second number is even." << std::endl;
    }
    std::cout << "--------------------------------------\n";
   
   
    //The Next part of your code doesn't make much sense because up at
    //The top we already declared whether or not the first number was
    //Bigger then the second one. So the whole equal to or greater then
    //thing wouldn't work. So we will skip that.
    //We will instead go to the positive or negative part of the code
   
   
    if ((fNum > 0) && (sNum > 0))
    {
         //If both the first number "AND" second number are above 0
         //Then do the following:
         std::cout << "Both numbers are positive Numbers!" << std::endl;
    }
    else if ((fNum > 0) && (sNum <= 0))
    {
         //If the first number is greater then 0 "AND" the second number
         //Is equal to or less then 0 then do the following:
         std::cout << "The first number is positive," << std::endl;
         std::cout << "but the second number is not." << std::endl;
    }
    else if ((fNum <= 0) && (sNum > 0))
    {
         //If the first number is less then or equal to 0
         //"AND" the second number is greater then 0 do the following:
         std::cout << "The first number is negative," << std::endl;
         std::cout << "but the second number is not." << std::endl;
    }
    std::cout << "--------------------------------------\n";
   
   
    //Now on to the difference part of the if statement.
    //I would just stick with the difference of the numbers once.
    //So instead of getting a - b and b - a. You should just find
    //Which one is bigger and then subtract the other from it.
    //Here is how I would do it using if statments.
   
   
    if (fNum > sNum)
    {
         //If the first number is greater then the second number
         //Then do the following:
         std::cout << "The difference between the two numbers" << std::endl;
         std::cout << "is " << fNum - sNum << std::endl;
    }
    else if (fNum < sNum)
    {
         //If the first number is less then the second number
         //Then do the following:
         std::cout << "The difference between the two numbers" << std::endl;
         std::cout << "is " << sNum - fNum << std::endl;
    }
    std::cout << "--------------------------------------\n";
   
    //Then you can also use the same technique to get the a / b
    //But because these are integers they will come out all messed
    //Up if they don't divide evenly like if its 5 / 3
    //So I will end it here.
   
    std::cout << "This is the end of my program!" << std::endl;
   
    //I hope you got something out of it dude. I'm happy to help.
    //So ask away if you have any more questions.     
         
   
   
    char f;
    std::cin >> f;
    return 0;
}
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

Next

Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests