First assignment

--Originally published at The Clueless Programmer

I see you came back for more of my programming magic, welcome. Ok what I have for you today is certainly a more difficult program than the “Hello World” one, but was still fairly easy to program.

Basically the assignment asked us to make a program that asks the user to input two numbers, and the sums, substracts, multiplies and divides them giving us all the different results. This is an example of the program with two numbers I chose randomly:

sin-titulo

#include <iostream>
using namespace std;
int main()
{
int num1, num2, res;
cout<<“Please enter a number “<<endl;
cin>>num1;
cout<<“The number you entered is “<<num1<<endl;
cout<<“Please enter a second number “<<endl;
cin>>num2;
cout<<“The number you entered is “<<num2<<endl;
res=num1+num2;
cout<<“The sum of “<<num1<<” + “<<num2<<” is “<<res<<endl;
res=num1-num2;
cout<<“The difference of “<<num1<<” – “<<num2<<” is “<<res<<endl;
res=num1*num2;
cout<<“The product of “<<num1<<” * “<<num2<<” is “<<res<<endl;
res=num1/num2;
cout<<“The integer based division of “<<num1<<” divided by “<<num2<<” is “<<res<<endl;
res=num1%num2;
cout<<“The remainder integer of “<<num1<<” divided by “<<num2<<” is “<<res<<endl;
}

As you can see, the program asks you to give it two numbers and then, because it is super smart, does the operations for you, so if one day you donĀ“t feel like doing simple math then all you have to do is turn on your computer and open this program! Way cooler than a calculator am I right?

I basically named the variables first, then asked the user to input two numbers, the parts where I printed a lot of useless information was just to try out some output stuff, they are not really necessary. Then you just do the operations, saving them on the variable, and print them, easy. I was able to program this easily because of the previous knowledge I had acquired on a course I took

Continue reading "First assignment"