|
With this code, note I modified some of it, you have to press 1 then enter to then enter a number that you want to have cubed. It doesn't loop like it should. Either it doesn't work, or I am doing something wrong. ![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
Can you explain what does what in the code. Its more basic then I originally thought it would be to do calculator functions, or at least one of them. I would like to make a calculator that adds, subtracts, multiplies, and divides. I modified the code once more just to mess around with it because I wanted to see if it could find pi but it didn't do any decimal points. Is there some other code that is needed to do this? How do I make options? You have it so that when you press "1" and then "enter" you can then start and input the number that you want to be cubed. I would like it so that when you select on the the functions by "+, -, *, /" and then enter, it switches to that function. I think that this will be a simple first project based on the code you have provided.
![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
*shreds*
|
Post the code that you used for the pi thing? You probably made the variable the wrong type or something. Also on options, if I understand you correctly you want to have an easy way to have different options on an input field. As far as I know there is no way to do this. You just have to process the input and decide which function to use or to return an error of some sort. I can't really give you a specific c++ example, I use c mostly, but here is a general example: Code// a = whatever input you had // var3 = final answer // var1 and var2 = number inputs if(a == 1) // there may be something more you have to do here var3 = var1 + var2; else if(a ==2) var3 = var1 - var2; else cout << "Invalid Input"; // this might be wrong, i don't use c++ ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|
You can't use decimals with 'int". They're a different variable type called "float" and I would suggest you not use them for now.
Here: Code// While loop example #include <iostream> using namespace std; int main () { int b, c = 1; cout << "Go" << endl; while (true) //whatever is in the parenthesis must evaluate to true for this to continue looping. refer to boolean algebra. if (c==1) //check for command value (value of c) { cout << "Input a number to be cubed." << endl; cin >> b; //get b cout << b * b * b << endl; //cube b cout << "Press 1 if you wish to go again" << endl; cin >> c; //get c } else if (c != 1) //quit if c is not equal to 1 { return 0; } } This post was edited 3 times, last edit by cheeze: May 25 2008, 9:06 pm.
![]() ![]() ![]() ![]() ![]() ![]() |
|
I want to do some of this on my own but with help here and there. I want to make a calculator that does whole numbers and that can be switched throughout the process by hitting either + - * - or ^. I know how to manually set up the equation but I don't know how to code it.
Addition " + " cout << a + b ; "\n"; Subtraction " - " cout << a - b ; "\n"; Multiplication " 8 " cout << a 8 b ; "\n"; Division " / " cout << a / b ; "\n"; Exponent " ^ " I'm not sure how to set this up for every situation. I want it to be something like Enter A, then Enter B and what ever B is equal to that will be your exponent. EX: A = 3 B = 4 Equation 3 * 3 * 3 * 3 How would I increase the amount of times B is? Like if B = 1 then A = Answer. If B = 2 A * A = Answer. If B = 3 A * A * A = Answer. I'm pretty sure you don't have to make every possible equation for each outcome. ![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
When it comes to stuff you don't know, and trust me there will always be stuff like this, you gotta start thinking with variables.
For instance //int a = Number //int b = Exponent //well, why not use a while statement? int i = 0; int NewNumber = 1;//Anything to the zero power is 1, lets take care of that here while(i != b) { NewNumber = NewNumber * a; i++; } cout << NewNumber; or a for statement to use less lines of code int NewNumber = 1; for(int i = 0; i != b; i++) { NewNumber = NewNumber * a; i++; } cout << NewNumber; ![]() ![]() ![]() ![]() ![]() ![]() |
|
I paid eleven minerals for THIS?
|
For the love of god, never use != as a control loop condition when a comparison operator will suffice. You're just begging for an accidental infinite loop.
![]() ![]() ![]() ![]() ![]() ![]() "Three can keep a secret, if two are dead." -Benjamin Franklin
"Had, having, and in quest to have, extreme; A bliss in proof, and proved, a very woe; Before, a joy proposed; behind, a dream. All this the world well knows; yet none knows well To shun the heaven that leads men to this hell." -William Shakespeare |
|
Yeah that happened to me a couple of times. I don't know any of the code I will just copy and modify what I already have to fit my needs. I need to set up some sort of menu. Something like a message that appears like: Select your operand by either selecting + - * / and hit enter.
![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
How do I set it up for multiple equations? I want it to at least do addition, subtraction, multiplication, and division. I want it to be able to be selected either by typing it in, or by selecting one of the symbols. How do I set it up for it to recognize the new equation and then changing it to the one chosen? I would also like it to remove previous text after I have done one of the equations and then hit 1 again to loop the program? What is the largest number that you can input into this? I put in a ridiculous number and it repeated into infinity and never stopped.
![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
Well, you had one if statement for cubed.
To implement subtraction, just put another if statement in there that does something like a = b - c and print out a. Similarly, do this for addition, multiplication and division. Note that with integer division, it'll remove the decimal (that is, 4/3 = 1). Like I said, do not worry about exponents for now; make sure we can get the basic control flow going before implementing cool stuff. Here's a simple example of if else statements: Codeif ([i]condition[/i]) { //[i]perform action here[/i] } else if ([i]another condition[/i]) { //[i]perform another action here[/i] } ![]() ![]() ![]() ![]() ![]() ![]() |
|
cout << "Please Input A ( 1-10 )." << endl; = Display Text
cin >> a; //get a = Last inputed number cout << a + b << endl; = Equation How do I make it erase all of the text and start over? When the end of the equation occurs and you are asked again to select the next operand by pressing 1-4, how do I make this action loop when 1-4 is False? (the person did not hit 1-4) It locks up on me and then I have to restart the whole thing. It actually works nicely. This is way easier to make then Tuxlar's Binary Calculator Map... LULZ ![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |