Heya, guys. I've been doing pretty well, lately with the whole C++ thing. I've been getting the hang of it, and so I'm really happy. I've trying to push myself, and so I made a calculator program that does the basic four operator stuff with two numbers, but now I want to test my Loop Skills (Which I have barely any) and create Exponents.
My first question is: Do I use a For Loop or a While Loop? Why?
Right here is my code, and I just want to know if this seems on track SO FAR. Please do not tell me the answer, because I'm trying to push myself. Thanks a lot! The Loop section isn't done because I'm stuck. I just need to think it out, but I want to know if I use a For Loop or a While Loop.
#include <iostream>
usingnamespace std;
int main()
{
int firstNumber;
int yesNo;
int exponentTimes;
int secondNumber;
int operatorNumber;
cout << "Hello, user! Today we will be using a very basic calculator." << endl;
cout << "Hit ENTER to continue." << endl;
cin.get();
cout << "Do you mind printing in your first number: ";
cin >> firstNumber;
cout << "\n\n Would you like to multiply this number with exponents? (1 for yes, 0 for no)" << endl;
cin >> yesNo;
if (yesNo == 1){
for // Is this the correct Loop?
}
cout << "\nNow, please enter your second number that you would like to use: ";
cin >> secondNumber;
cout << "\n\nGreat! So, please enter the number corresponding to the operator below: " << endl;
cout << "1. +\n2. -\n3. *\n4. /" << endl;
cin >> operatorNumber;
if (operatorNumber == 1){
cout << "The sum of the two numbers is: " << firstNumber + secondNumber << endl;
}
elseif (operatorNumber == 2){
cout << "The difference of the two numbers is: " << firstNumber - secondNumber << endl;
}
elseif (operatorNumber == 3){
cout << "The product of the two numbers is: " << firstNumber * secondNumber << endl;
}
elseif (operatorNumber == 4){
cout << "The quotient of the two numbers is " << firstNumber / secondNumber << endl;
}
else {
cout << "I'm sorry, you entered a number that is not on the list, please try again." << endl;
}
return 0;
}
I don't understand what you mean by 'do you want to multiply this number with exponents', but I can tell you that either loop will work. The one you choose depends on how you have it set up so far, there is no right or wrong kind of loop to use.
Alright, I worded it wrong. By the User will chose one number, say "5". The next number will be the power of that number. Let's say the user chooses 6.
So, it'll be 5^6. (5*5*5*5*5*5).
That's my new project, using exponents with loops, but I don't really know how to use loops that well. So is there anyone that can point me to a tutorial or maybe help me out? Give me a little boost, and I'll see if I can finish it? Any help would be appreciated. Just don't finish the entire code, please.