Quote
Is the product of 5 positive numbers and 6 negative numbers a positive or negative number?
#include<iostream>
using namespace std;
int main()
{
int firstnumb = 0;
int secondnumb = 0;
int answer = 0;
char again = 'y';
while(again == 'y')
{
cout << "\n\tPositive Negitive Calculator." << endl;
cout << "\nHow many positive numbers? ";
cin >> firstnumb;[COLOR="green"]//This is never used to calculate any thing.[/COLOR]
cout << "\nHow many negative numbers? ";
cin >> secondnumb;[COLOR="green"]// This is how many time we times -2 * -2.[/COLOR]
if (secondnumb >= 0)[COLOR="green"]//Makes sure they entered a number above 0.[/COLOR]
{
int i;
answer = 2;
for (i = 0; i < secondnumb; i++) {
answer *= -2;[COLOR="green"]//This takes answer which equals 2 and times it times -2 intel i reaches secondnum.[/COLOR]
}
}
if (answer <= 0)[COLOR="green"]//If or answer is below 0 then tell the user its negative.[/COLOR]
{
cout << "\nYour answer is negative." << endl;
}
else if (answer >= 0)[COLOR="green"]//If or answer is above 0 then tell the user its positive.[/COLOR]
{
cout << "\nYour answer is positive." << endl;
}
cout << "\nDo you want to make another calculation? (y/n) ";
cin >> again;
}
cout << "OK maybe next time." << endl;
cin.get();
return 0;
}
Well that's it it's actually pretty easy so now you know how to make a negative or positive calculator if for some odd reason you wanted one, leave your comments about the program.:)BTW Thanks Orjan for helping me with the variables.^^


Sign In
Create Account


Back to top









