Black Magic 15 Junior Poster

Hey,
I was using some code to write int's defined by user to a file but found when you use

myfile.open ("lover_names.txt");
    myfile << firstLover << " " << secondLover << " " << lovePercent << "%\n\n";
    myfile.close();

It replaces the other text in the text file, the answer will most likely be simple but i don't know it, Help ASAP?

Black Magic 15 Junior Poster

ok, thank you, ive decided to do whitch ever strategy is most effecdent, so would it be hammers idea?

Black Magic 15 Junior Poster

i like hammers idea but i think im going to go for maj's solution, how would i save the names to file? i know how to write like this is a line etc, would i just do that? oh and how would i pair the two names tomorrow?

Black Magic 15 Junior Poster

I get you, but not how to do that,

Could you please post a little example and then i would work on it from that

Thank you!

Black Magic 15 Junior Poster

Hey,
I was just mucking around and made a simple random number generator and made a "love percentage game" but, if you re-open the .exe and type the same names in it gives another completely different percentage, would i save the names to do a file or some kind?

#include <iostream>
#include <conio.h>
#include <time.h>

using namespace std;

int main()
{
    char firstLover[20];
    char secondLover[20];
    
    unsigned int lovePercent;
    
    cout << "Enter The First Lovers Name: ";
    cin  >> firstLover;
    
    cout << endl << "Enter The Second Lovers Name: ";
    cin  >> secondLover;
    
    srand ( time(NULL) );
    
    lovePercent = rand() % 100 + 1;
    
    cout << endl << "Your Love Percentage Is : " << lovePercent << "%!";
    
    getch();
}

Please reply with help, A.S.A.P :)

Black Magic 15 Junior Poster

Thank you!

#include <iostream>
#include <conio.h>

using namespace std;

class Cat
{
      public:
      
      unsigned int age;
      unsigned int weight;
      
      void Meow();
      void Feed();
      void Sleep();
};

void Cat::Meow()
{
     cout << "Meow" << endl;
}

void Cat::Feed()
{
     
     const char *Feed[] = 
     { 
           "Meoww (Cat's Happy To Eat)\n", 
           "Psshhh (Cat Is Not Hungry!)\n",
           "Zzz (The Cat's Asleep, Leave It Alone)\n"
           }; 
           
           cout << Feed[ rand() % 3 ];
}

void Cat::Sleep()
{
     cout << "Meowww Zzz (Cat Has Fallen Asleep)" << endl;
     cout << "Psshhh (The Cat Is Not Tired)" << endl;
     cout << "Zzz (The Cat Is Already Asleep)" << endl;
}

int main()
{
    Cat BlackMagic;
    
    BlackMagic.Feed();
    BlackMagic.Sleep();
    
    getch();
}

I didn't get the outcomes i wanted, it gave me some answers from Sleep and i put *Feed[] with the random ones?

Black Magic 15 Junior Poster

Hey guys,

I was just reading again about classes and their functions and i made some code, the thing i want to do is have a function, eg.

void Cat::Sleep()

and have it to have three cout's and choose one of them to say at random,

Heres my code.

#include <iostream>
#include <conio.h>

using namespace std;

class Cat
{
      public:
      
      unsigned int age;
      unsigned int weight;
      
      void Meow();
      void Feed();
      void Sleep();
};

void Cat::Meow()
{
     cout << "Meow" << endl;
}

void Cat::Feed()
{
     cout << "Meoww (Cat's Happy To Eat)" << endl;
     cout << "Psshhh (Cat Is Not Hungry!)" << endl;
     cout << "Zzz (The Cat's Asleep, Leave It Alone)" << endl;
}

void Cat::Sleep()
{
     cout << "Meowww Zzz (Cat Has Fallen Asleep)" << endl;
     cout << "Psshhh (The Cat Is Not Tired)" << endl;
     cout << "Zzz (The Cat Is Already Asleep)" << endl;
}

int main()
{
    Cat BlackMagic;
    
    BlackMagic.Feed();
    BlackMagic.Sleep();
    
    getch();
}
Black Magic 15 Junior Poster
int main()
{
    cout << (int)'£' << "\n";
    return 0;
}

The output of the above on my computer is -93. You'll have to change the local setting if you want to print that character from -93 because it doesn't print that with the standard American local setting.

My output is also -93, could you please show me how to change etc, many thanks

Black Magic 15 Junior Poster

>> fossil compiler.
I'm using dev-c++, just using that for getch();

So is there noway of getting £ into my program?

Black Magic 15 Junior Poster

Hey guys, i was bored so made a money converter, nothing is wrong with errors etc in the code but when i run my program, the pound sign is not valid, it comes up as a u with a accent on top, please help.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    unsigned int convertMoney;
    char moneySymbol;
    
    cout << "Enter whether you would like convert from £ / $ : ";
    cin  >> moneySymbol;
    
    switch (moneySymbol)
    {
           case '$':
           cout << endl << "Enter ammount to convert :";
           cin  >> convertMoney;
           cout << "$" << convertMoney << " = £" << (convertMoney * 0.508233381);
           break;
           
           case '£':
           cout << endl << "Enter ammount to convert :";
           cin  >> convertMoney;
           cout << "£" << convertMoney << " = $" << (convertMoney * 1.9676);
           break;
    }
    getch();
}

EDIT : I googled it and found this website, http://www.fileformat.info/info/unicode/char/00a3/index.htm
I looked and it told me to enter "\u00A3" for the pound sign, i did that put it came up with another symbol PLEASE HELP

Black Magic 15 Junior Poster

Hello,
I have decided to not use binary, i have added power and edited some of the set out,

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
     
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan, resultPower;
    
    char operation, boolSqrt; 
    
    cout << "\n  OPERATORS : +, -, *, /, !, ^, S, C, T" << endl;
    cout << "\n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  ^ = POWER\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);        
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan = tan (firstNumber*PI/180);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ADD : ";
                          cin  >> secondNumber;
                          cout << "\n EQUALS = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                          cout << "\n MINUS : ";
                          cin  >> secondNumber;
                          cout << "\n EQUALS = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x':
                          case 'X':
                          cout << "\n MULTIPLIED BY :  ";
                          cin  >> secondNumber;
                          cout << "\n EQUALS = " << (firstNumber * secondNumber);
                          break;
                          
                          case '/':
                          cout << "\n DIVIDED BY :  ";
                          cin  >> secondNumber;
                          cout << "\n EQUALS = " << (firstNumber / secondNumber);
                          break;
                          
                          case '!':
                          cout << …
Black Magic 15 Junior Poster

Oh, I've said to use pow before the user has entered the value, thank you hammerhead!

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

/*void binary(int);*/

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
     
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan, resultBinary;
    double resultPower;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    cout << "  OPERATORS : +, -, *, /, !, ^, S, C, T, B" << endl;
    cout << "\n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  ^ = POWER\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n  B = BINARY\n";
    
    cout << " \n ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);
        
    //resultBinary = binary (firstNumber);
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan = tan (firstNumber*PI/180);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << …
Black Magic 15 Junior Poster

Oops sorry.

I recompiled my program and went 6 ^ 2, and the answer was still one..

HELP?

Black Magic 15 Junior Poster

Just editing my calculator and looking at what functions math.h had and i came across pow,

My program compiles and things like that so no error but if I'm not mistaken the answer is wrong.

6 ^ 1 = 6X6? = 36 (IS THAT CORRECT??)

JUST IN MY PROGRAM IF I USE 6^1 IT GIVES ME 1

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

void binary(int);

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
     
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan, resultBinary;
    double resultPower;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    cout << "  OPERATORS : +, -, *, /, !, ^, S, C, T, B" << endl;
    cout << "\n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  ^ = POWER\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n  B = BINARY\n";
    
    cout << " \n ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);
    
    resultPower = pow (firstNumber, secondNumber);
    
    //resultBinary = binary (firstNumber);
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan …
Black Magic 15 Junior Poster

(SORRY FOR DOUBLE POSTING)

I have noticed i kept using "blackmagic.bat" and re-read the posts and i need a bin file, would i just create a file in notebook and save it as blackmagic.bin?

Black Magic 15 Junior Poster

Thank you all for all your help.

So people are mentioning editing the binary function, can you please show me how this could be done :S

Black Magic 15 Junior Poster

Sorry about saying spam, what i meant was ive already got that, but now the posts edited, thank you very much. In your opinion is it worth adding binary?

Black Magic 15 Junior Poster

It is in one case..

No offense but thats spam..

I need to know the answer for binary not something i already have..

Black Magic 15 Junior Poster

BUMP..

Hey,

Just tried adding Binary and got some errors :S

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

void binary(int);

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
    
    
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan, resultBinary;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    cout << "  OPERATORS : +, -, *, /, !, S, C, T, B" << endl;
    cout << " \n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n  B = BINARY\n";
    
    cout << " \n ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);
    
    resultBinary = binary (firstNumber);
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan = tan (firstNumber*PI/180);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                               cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x': …
Black Magic 15 Junior Poster

So..

myfile.open ("blackmagic.bat");

Is that not any good?

Black Magic 15 Junior Poster

Cool :D.

Thank you.

I kind of said no code, but when opening the file would i just use

myfile.open ("blackmagic.bat");

Many thanks.

Black Magic 15 Junior Poster

So, what would be the best solution?

Black Magic 15 Junior Poster

Hey,

Say if i made a program where people could register a account, but if they closed the window, the program would close and not remember passwords yeah? Well if i used the open file etc could i save the password's to a file so it remembered them?

Many Thanks.

PS. DO NOT POST CODE, I AM JUST ASKING

Black Magic 15 Junior Poster

>(Visual C++, I'm Guessing)

Nope, DEV_C++ :)

Black Magic 15 Junior Poster

Hey,
I was just mucking around when using rand() and noticed every time it comes out as a output of 41?

#include <iostream>

using namespace std;

int main()
{
    unsigned int randomNumber;
    unsigned int guess;
    unsigned int guesses;
    
    randomNumber = rand(); 
    cout << randomNumber << endl;
    
    system("PAUSE > nul");
}

Should i use srand() or something?

Black Magic 15 Junior Poster

Ok, sorry about that, is it because i didn't use typedef?

Black Magic 15 Junior Poster
#include <iostream>

using namespace std;

double FindArea();

int main()
{
    double width, lenght, area;
    
    cout << "How Wide Is Your Yard? : ";
    cin  >> width;
    cout << endl << "How Long Is Your Yard? : ";
    cin  >> lenght;
    
    area = FindArea(width, lenght);
    
    cout << endl << endl << "Your Yard Is " << area << " Square Feet!";
}

double FindArea(double& l, double& w)
{        
         return l * w;
}

NOW I GET to many arguments to function `double FindArea()'

Black Magic 15 Junior Poster

thats the whole example..

http://newdata.box.sk/bx/c/htm/ch05.htm

Click on the link : Listing 5.1.

I really like the book as well, its fine except from that example i think

Black Magic 15 Junior Poster

Hi,

I've been reading "C++ In 21 Days", I read functions a while back and decided to write some, i wrote the code and it gave me a error, so i copied and pasted code from the book and still got a error, you must see from my point of view if I'm learning a language i don't want to be tought the wrong things, thats like learning French and saying "Hallo" is hello, though the real hello is "Bonjour".

Heres the code non the less..

#include <iostream>

using namespace std;

unsigned short FindArea();

int main()
{
    unsigned short width, lenght, area;
    
    cout << "How Wide Is Your Yard? : ";
    cin  >> width;
    cout << endl << "How Long Is Your Yard? : ";
    cin  >> lenght;
    
    area = FindArea(width, lenght);
    
    cout << endl << endl << "Your Yard Is " << area << " Square Feet!";
}

unsigned short FindArea()
{
         unsigned short l, w;
         
         return l * w;
}

"too many arguments to function `short unsigned int FindArea()'

Black Magic 15 Junior Poster

this challenging code your homework by any chance?

Black Magic 15 Junior Poster

I'll try to add that :).

BTW, Do you think the layout is ok or should be changed a little?

Black Magic 15 Junior Poster

EDIT: GOT SIN, COS, AND TAN IN!!

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>

using namespace std;

#define PI 3.14159265

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
    
    
    double firstNumber, secondNumber;
    double resultSqrt, resultSin, resultCos, resultTan;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    cout << "  OPERATORS : +, -, *, /, !, S, C, T" << endl;
    cout << " \n";
    
    cout << "  + = ADD\n  - = SUBTRACT\n  * = Multiplication\n  ";
    cout << "/ = Division\n  ! = SQAURE ROOT\n  S = SIN\n  ";
    cout << "C = COS\n  T = TAN\n";
    
    cout << " \n ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    resultSqrt = sqrt (firstNumber);
    
    resultSin = sin (firstNumber*PI/180);
    
    resultCos = cos (firstNumber*PI/180);
    
    resultTan = tan (firstNumber*PI/180);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                               cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x':
                          case 'X':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer …
Black Magic 15 Junior Poster

Nice to see it working.
So jw, but was it homework or just boredom :)?

Black Magic 15 Junior Poster

Maybe because you have "30" in your code?

If you don't need it get rid of it, else put a ; on end of 30

Black Magic 15 Junior Poster

Thanks for the help, and yes i did change my post/code, Ive got to go now but when i return i'll add the options :) Thanks for all your help. I quite like my little program :)

Black Magic 15 Junior Poster

Thanks,

Ive changed code to case sqrt..

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>
using namespace std;

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
    
    
    double firstNumber, secondNumber, result;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    
    cout << " *****************************************" << endl;
    cout << "  OPERATORS : +, -, *, /, ! = SQUARE ROOT" << endl;
    cout << " *****************************************\n\n";
    
    cout << " ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;;
    cout << " ************************************************\n\n";    
       
    cout << "\n ENTER FIRST NUMBER  : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    result = sqrt (firstNumber);
    
         switch(operation)
         {
                          case '+':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                               cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x':
                          case 'X':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber * secondNumber);
                          break;
                          
                          case '/':
                          cout << "\n ENTER SECOND NUMBER : ";
                          cin  >> secondNumber;
                          cout << "\n Answer = " << (firstNumber / secondNumber);
                          break;
                          
                          case '!':
                          cout << "\n ANSWER = " << result;
                          break;
                          
                          default:
                          cout << "\n Wrong …
Black Magic 15 Junior Poster

THANK YOU!

Now i'll move onto sin, cos and tan.

But would i do the same thing?

Like Y/N because what happens if they input two Y's for different things?

Because atm my program only takes 2 integers (or 1 for square rooting)

Black Magic 15 Junior Poster
if ( boolSqrt != 'Y' || boolSqrt != 'y' && boolSqrt != 'N' ||
              boolSqrt != 'n')
         {
         cout << "\n WRONG DECISION.";
         }

Still doesn't work..?

Black Magic 15 Junior Poster

EDIT!!!

Got sqrt working!! WOO :)

#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>
using namespace std;

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR C");
    
    
    double firstNumber, secondNumber;
    char operation, boolSqrt; 
    
    cout << " *****************************************" << endl;;
    cout << "  Kizzop Productions - Simple Calculator!" << endl;;
    cout << " *****************************************\n\n"; 
    
    
    cout << " ************************" << endl;
    cout << "  OPERATORS : +, -, *, /" << endl;
    cout << " *************************\n\n";
    
    cout << " ************************************************" << endl;
    cout << "  NOTE : YOU CAN USE X AND x FOR MULTIPLICATION!" << endl;;
    cout << " ************************************************\n\n";
    
    cout << " Do you wish to use square root? Y, N : ";
    cin >> boolSqrt;
    
    if( boolSqrt == 'Y' || boolSqrt == 'y' )
    {
        cout << "\n\n ENTER NUMBER : ";
        cin  >> firstNumber;
        
        
                                  
        
        double result;
        
        result = sqrt (firstNumber);
        cout << "\n ANSWER = " << result;
                                 
                                  
   }    
      
    if( boolSqrt == 'N' || boolSqrt == 'n' )
    {
       
    cout << " ENTER FIRST NUMBER : ";
    cin  >> firstNumber;

    cout << "\n ENTER OPERATOR SIGN : ";
    cin  >> operation;
    
    cout << "\n ENTER SECOND NUMBER : ";
    cin  >> secondNumber;
    
         
         switch(operation)
         {
                          case '+':
                          cout << "\n Answer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                          cout << "\n Answer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          case 'x':
                          case 'X':
                          cout << "\n Answer = " << (firstNumber * secondNumber);
                          break;
                          
                          case '/':
                          cout << "\n Answer = " << (firstNumber …
Black Magic 15 Junior Poster

Could i not add a bool or something?

Black Magic 15 Junior Poster

Sorry for misunderstanding. Thanks for the multiplication classes, would it be "hard" to add sin, cos and tan?

Black Magic 15 Junior Poster

>Will they be an improvement? Probably not

I am going to improve it yes. I am going to make it have more options, square root, etc etc

Black Magic 15 Junior Poster

Hey, i was just messing around and made a calculator and was just wondering if there was a way i could make it shorter? I'm not really bothered i just want to know?

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    system("TITLE My Calculator Program.");
    system("COLOR 4");
    
    double firstNumber, secondNumber;
    char operation; 
    
    cout << "NOTE: YOU CAN USE X/x INSTEAD OF * FOR MULTIPLICATION!\n\n\n\n";  
    
    cout << "Please enter the first number : ";
    cin  >> firstNumber;
    
    cout << "\nWhich type of calculation would you like to use? : "; 
    cin  >> operation;
    
    cout << "\nPlease enter the second number : ";
    cin  >> secondNumber;
    
         
         switch(operation)
         {
                          case '+':
                          cout << "\nAnswer = " << (firstNumber + secondNumber);
                          break;
                          
                          case '-':
                          cout << "\nAnswer = " << (firstNumber - secondNumber);
                          break;
                          
                          case '*':
                          cout << "\nAnswer = " << (firstNumber * secondNumber);
                          break;
                          
                          case 'x':
                          cout << "\nAnswer = " << (firstNumber * secondNumber);
                          break;
                          
                          case 'X':
                          cout << "\nAnswer = " << (firstNumber * secondNumber);
                          break;
                          
                          case '/':
                          cout << "\nAnswer = " << (firstNumber / secondNumber);
                          break;
                          
         }
         
         system("PAUSE > nul");
}

Thanks.

Black Magic 15 Junior Poster

I never said i cant use sqrt() i just said i dont know if it's worth it

Black Magic 15 Junior Poster

I've looked at websites etc, but tbh is it worth it?

Black Magic 15 Junior Poster

Thanks but i think i'll leave that option out

Black Magic 15 Junior Poster

Hey i've made a simple calculator, but i was thinking about adding a square root option..

But is there a actual way to do this or would i have to create my own??

PLEASE REPLY A.S.A.P

Black Magic 15 Junior Poster

Actually i'm trying to improve this now, i've figured i'll need a loop?

Because i want to change it so that if the user inputs a different char/int than Y/N it will cls and re-ask question,

Heres what i've got

/* Simple users decision to exit program */

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char exit;
    
    cout << "Exit? Y / N " << endl;
    cin >> exit;
    
    if ( exit == 'Y' || exit == 'y' )
       { }
       
    if ( exit == 'N' || exit == 'n' )
        getch();
        
    else
        system("cls");
        cout << "Exit? Y / N " << endl;
        cin >> exit;

}

If the user enters another char/int it cls's and asks again but if they enter a char/int again it closes, please help :)

Black Magic 15 Junior Poster

Thanks! Just one thing, would i use a array to make the password a maximum of 20? Or ..?

Please show code. :)

Black Magic 15 Junior Poster

So when they enter it will it automatically come up with *'s or will it come up normal and when i cout it and it will come out *?

Because ideally i would like no normal letters, just *'s :)