Advertisements

Calculating the sum of the difference of two intergers

    // Programmer:
// Program purpose: Lab_on_For_Loops 3/14/12

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
   int num1 = 0,   //assignment for intgers and bool
      num2 = 0,
      result,
      sum = 0,
      number1;
   bool notevil = false;

   cout <<”       1.) Get the sum of two numbers”<<endl; //starting menu
    cout <<”       2.) Exit Program”<<endl;

    cout <<“Enter a number from the menu to select”; //asking for a selection
    cout <<endl;
    cout <<endl;
    cin >> number1;

    switch (number1) // switches number one with a number
    {
      case 1: notevil = false; // switches number1 to true
         break;
      case 2: notevil = true;
         break;
    }

  
    while(notevil == false) // if #1 is selected go into the “if” statement
   {
      num1 = num2 = sum = 0;

      cout <<“Please enter your first number”<<endl;// ask user for first number
      cin >> num1;
   
   while(num2 < num1)
   {
      cout <<“Please enter your second number”<<endl;// ask user for second number
      cin >> num2;                                  
   }

   for(result = num2 – num1; result >= 0; result–) //declaring result as the difference between 2 numbers
      {
     
      sum += result + num1; // calculations to add the difference of the numbers
     
      }

   cout << sum <<endl; //displays teh difference of your 2 numbers

   cout <<”       1.) Get the sum of two numbers”<<endl; //starting menu
    cout <<”       2.) Exit Program”<<endl;

    cout <<“Enter a number from the menu to select”; //asking for a selection
    cout <<endl;
    cout <<endl;
    cin >> number1;

    switch (number1) // switches number one with a number
    {
      case 1: notevil = false; // switches number1 to true
         break;
      case 2: notevil = true;
         break;
    }

  }
 
   
            
   
   system(“pause”);
   return 0;
}

   
            
 

Advertisements

About Rant4u

A Revolution in Social Networking

Posted on March 15, 2012, in #c++ calculations, #c++ for loops, #C++ programming, #c++ while loops, #rant-4u. Bookmark the permalink. Leave a comment.

Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: