Write a program which takes two integers (num1 and num2) as input from the user.
Your program should display on the screen the result of i) num1 + num2, ii) num1 * num2, and iii) num1 - num2.
You are not allowed to use the + or - or * operators. E.g., cout<<num1+num1<<num1*num2<<num1-num2; is not allowed. += or -= or *= operators are also not allowed.
You HAVE TO USE loops and the ++ and -- operators. Code for num1+num2 is already available in the slides. Use that for this assignment.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
int a,b,c,d;
a = 0;
b = 0;
c = 0;
d = 0;
cout << "Enter Num1..." << endl;
cin >> num1;
cout << "Enter Num2..." << endl;
cin >> num2;
while (a < num1)
a++;
while (b < num2)
{
a++;
b++;
}
cout <<"1)The amount = "<< a << endl;
for (int i = 0; i < num1; i++)
for (int j = 0; j < num2; j++)
d++;
cout << "2)The product = " << d << endl;
if (num1>num2)
{
b = num1;
a = num2;
while (a != b)
{
c++;
b--;
}
}
else
{
b = num2;
a = num1;
while (a != b)
{
c++;
b--;
}
}
cout << "3)The difference = " << c << endl;
system("Pause");
return 0;
}
Comments
Leave a comment