Division program – C++

What it does:

A easy C++ division program where the user is prompted to enter two numbers. The program will then divide them with each other and print out the result to the user.

Code:



#include <iostream>
using namespace std;

int main()
{
    //Creating variables  
    double firstNumber, secondNumber, result;

    cout << "Welcome to C++ division program" << endl;
    
    //prompting user to enter first number
    cout << "Please enter your first number" << endl;
    
    //read in for first number
    cin >> firstNumber;
    
    //prompting user for second number
    cout << "Please enter your second number" << endl;
    
    //read in for second number
    cin >> secondNumber;
    
    //Caculation
    result = firstNumber / secondNumber;
    
    //printing out the result
    cout << "Result " << result << endl;
    
    return 0;
}//main

3 thoughts on “Division program – C++

  1. It’s important that you check if the divisor is 0 or not, or else you might get a very unexpected response. 🙂

Leave a 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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s