Simple Math Program

A simple math program I wrote that performs addition, subtraction, multiplication, and division using two numbers that you input.

Screenshot of Program:

http://i.imgur.com/ARa6V.png


Raw Code:

#include<iostream>
using namespace std;

int main()
{
float num1;
float num2;

//Intro for program
cout<<"\n**SIMPLE MATH**\n\nWritten by Sam Devanski for C++ class\n\n";
cout<< "Welcome to my simple math program.\nThis program will perform various mathematical operations using two numbers that you input.\n";

//Prompts for input numbers
cout<<"\nPlease type your first number.\n";
cin>>num1;
cout<<"\nPlease enter your second number\n";
cin>>num2;

//Restates the numbers that you typed
cout<<"\nYour two numbers are "<<num1<<" and "<<num2<<".\n\n";

//Displays solutions to +,-,*,/ operations using your input numbers
cout<<num1<<" plus "<<num2<<" equals "<<num1+num2<<"\n";
cout<<num1<<" minus "<<num2<<" equals " <<num1-num2<<"\n";
cout<<num1<<" times "<<num2<<" equals " <<num1*num2<<"\n";
cout<<num1<<" divided by "<<num2<<" equals " <<num1/num2<<"\n";

cout<<"\n\nPress any key and then ENTER to exit.\n";
cin >> num1;
return 0;
Last edited on
Congratulations on your first release !

Could you explain to me why num1/num2(5/3) is equal to 1? What happened to the remainder? How would I go about obtaining this information?

What happens if you change the types of num1 and num2 to type double(instead of int) ?
Changing the int to a float allows the division to happen correctly
Last edited on
Topic archived. No new replies allowed.