Programing
May 20 2008, 11:48 pm
By: Brontobyte
Pages: < 1 « 4 5 6 7 >
 

May 25 2008, 5:02 am Brontobyte Post #101



It still had an error.



None.

May 25 2008, 5:04 am WoAHorde Post #102



Quote from Epsilonite
Line 20
Code
cout << b * b * b "\n";
should be replaced with this:
Code
cout << b * b * b << "\n";

No, you don't have to do that. It runs perfectly on Dev-C++.



None.

May 25 2008, 5:12 am Brontobyte Post #103



It worked fine the one way but then I tried it again from your version then added DC_BK's stuff, then the other fix and it didn't work, even when I went back to the original. Yes I'm using Dev C++ And how is 52 = 125? Isn't 5x5=25?? <.<

It should be:

Quote
cout << b * b << "\n";

Where "b" equals the number inputed on command.



None.

May 25 2008, 5:19 am Brontobyte Post #104



Quote
// While loop example
#include <iostream>

using namespace std;

int main ()

{
int a,b,c;
a = 1;

cout << "Go and type in the number 1" "\n";
cin>> c;
cin.ignore();

while (a==1)

if (c==1) {
cout << "Input a number to be cubed." "\n";
cin>> b;
cout << b * b << "\n";
cin.get();
cout << "Press 1 if you wish to go again" "\n";
cin>> c;
cin.get();
}
else if (c > 1, c < 1) {
return 0;
}

}

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.



None.

May 25 2008, 5:28 am WoAHorde Post #105



I said a number cubed, not squared.



None.

May 25 2008, 5:52 am WoAHorde Post #106



Quote from WoAHorde
Code
// While loop example
#include <iostream>

using namespace std;

int main ()

{
   int a,b,c;
   a = 1;
   
   cout << "Go" "\n";
   cin>> c;
   cin.ignore();
   
   while (a==1)
   
   if (c==1) {
      cout << "Input a number to be cubed." "\n";
      cin>> b;
      cout << b * b * b; "\n";
      cin.get();
      cout << "Press 1 if you wish to go again" "\n";
      cin>> c;
      cin.get();
      }
   else if (c > 1, c < 1) {
        return 0;
        }

}


A quick program I made to demonstrate.

Fix'd a possible error in my hasty coding, try it again.



None.

May 25 2008, 12:26 pm Brontobyte Post #107



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.



None.

May 25 2008, 6:42 pm Money Post #108



Quote from Brontobyte
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.

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++




None.

May 25 2008, 7:20 pm Brontobyte Post #109



Quote
// While loop example
#include <iostream>

using namespace std;

int main ()

{
int a,b,c;
a = 1;

cout << "Go" "\n";
cin>> c;
cin.ignore();

while (a==1)

if (c==1) {
cout << "Input a number to be cubed." "\n";
cin>> b;
cout << b / 7 * b; "\n";
cin.get();
cout << "Press 1 if you wish to go again" "\n";
cin>> c;
cin.get();
}
else if (c > 1, c < 1) {
return 0;
}

}




None.

May 25 2008, 8:49 pm cheeze Post #110



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;
  }
}


Post has been edited 3 time(s), last time on May 25 2008, 9:06 pm by cheeze.



None.

May 25 2008, 10:44 pm Brontobyte Post #111



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.



None.

May 25 2008, 11:04 pm cheeze Post #112



For now, don't worry about exponents (they're a little trickier) and don't worry about using "+" for addition or "-" for subtraction. Just substitute with integers, see if those work. If it does, it's just a quick change to strings.



None.

May 26 2008, 12:08 am Cole Post #113



Quote
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;



None.

May 26 2008, 1:03 am DT_Battlekruser Post #114



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.



None.

May 26 2008, 1:31 am Brontobyte Post #115



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.



None.

May 26 2008, 1:58 am Cole Post #116



Quote from DT_Battlekruser
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.
Haha, you're right. I never remember though. Thankfully I compile & test often and try to debug for every scenario.



None.

May 26 2008, 3:46 am Brontobyte Post #117



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.



None.

May 26 2008, 6:25 am cheeze Post #118



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:
Code
if ([i]condition[/i])
{
  //[i]perform action here[/i]
}
else if ([i]another condition[/i])
{
  //[i]perform another action here[/i]
}




None.

May 26 2008, 1:37 pm Brontobyte Post #119



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

Calculator Program




None.

May 26 2008, 2:24 pm Money Post #120



Your comments are a bit wrong. Also, why can A or B only be 1 - 10 ?



None.

Options
Pages: < 1 « 4 5 6 7 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[05:59 am]
NudeRaider -- *is
[05:17 am]
NudeRaider -- despite all its flaws the sound design its fantastic
[10:29 pm]
Oh_Man -- homeworld 3 = massive disappointment
[2024-5-14. : 10:05 am]
Moose -- ya
[2024-5-14. : 5:23 am]
zsnakezz -- yes
[2024-5-12. : 8:51 pm]
l)ark_ssj9kevin -- Are you excited for Homeworld 3?
[2024-5-12. : 8:44 pm]
l)ark_ssj9kevin -- Hi Brusilov
[2024-5-12. : 4:35 pm]
O)FaRTy1billion[MM] -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
my server that was hosting it died
[2024-5-10. : 8:46 pm]
NudeRaider -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
https://armoha.github.io/eud-book/
[2024-5-10. : 8:36 am]
Brusilov -- Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
Please log in to shout.


Members Online: Moose