• Welcome to Valhalla Legends Archive.
 

My First c++ application

Started by BaDDBLooD, August 21, 2004, 02:15 PM

Previous topic - Next topic

BaDDBLooD



#include <iostream.h>

int main()
{

   int choice;
   int number1;
   int number2;
   char indicator;

   cout << "1) Addition" << endl
       << "2) Subtraction" << endl
        << "3) Multiplication" << endl
        << "4) Division" << endl;

   do
   {
      cout << "Enter First Digit: ";
      cin >> number1;

      cout << "Enter Second Digit: ";
      cin >> number2;

      cout << "Choose Operator: ";
      cin >> choice;

      switch(choice)
      {
         case 1: cout << endl << "The answer is: " << number1 + number2 << endl;                  
               break;
         case 2: cout << endl << "The answer is: " << number1 - number2 << endl;                   
               break;
         case 3: cout << endl << "The answer is: " << number1 * number2 << endl;                   
               break;
         case 4: cout << endl << "The answer is: " << number1 / number2 << endl;                   
               break;
         default: cout << endl <<"You chose invalid selection" << endl;
      }

      cout << endl << "Do you want to enter another (y or n)? ";   
      cin >> indicator;
      cout << endl;
   } while((indicator == 'Y' || indicator == 'y'));

  return 0;
}



Suggestions / Comments Apreciated!
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

iago

#1
It's better than Mephisto's :D

<edit> Don't take any of his advice in that thread, please.  It's not very good.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Sargera

#2
Quote from: BaDDBLooD on August 21, 2004, 02:18 PM
Lmao! wow that is really bad!

Actually, I just think you're stupid and agreeing with iago.  It's generally shit, and thanks again, iago (*grins*) for bringing that up again.  With a few edits of that calculator (bad coding, like recursing main and the array usage which I don't actually mind doing in such an insignificant application) and it's fine.  :)

Edit: Your calculator is no better than someone elses who is starting out in C++.  Oh yeah, and you might want to use ANSI C++ :)

iago

Quote from: Sargera on August 21, 2004, 02:32 PM
Quote from: BaDDBLooD on August 21, 2004, 02:18 PM
Lmao! wow that is really bad!

Actually, I just think you're stupid and agreeing with iago.  It's generally shit, and thanks again, iago (*grins*) for bringing that up again.  With a few edits of that calculator (bad coding, like recursing main and the array usage which I don't actually mind doing in such an insignificant application) and it's fine.  :)

Edit: Your calculator is no better than someone elses who is starting out in C++.  Oh yeah, and you mind want to use ANSI C++ :)

I think his is perfectly good :)

And lol @ you replying so fast.  I was going to aim you soon, but I was eating pizza :(

Pizza > Mephisto
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


BaDDBLooD

My Second Application:



#include <iostream.h>

int main()
{
   char indicator = 'n';
   int value = 0;
   double f = 0;

   do
   {
      cout << endl << "Enter value: ";
      cin >> value;

      f=1;

      for(int i = 2; i<=value; i++)
         f *= i;

      cout <<  value << "! is " << f;

      cout << endl << "Do you want to enter another value (y or n)? ";
      cin >> indicator;

   } while((indicator=='y') || (indicator=='Y'));

   return 0;
}

There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Sargera

#5
Maybe you should use contemporary ANSI C++ :)

Also, your indents are inconsistant.  Should generally always use a 4-space tab.  Some people like to use 3-space tabs and 2-space tabs when indenting their conditional statements.

BaDDBLooD

#6
Eh.. it looks correct in vc++, it fucks up when i use code tags ;O

another program:



#include <iostream.h>

int main(void)
{
   int f = 0, c = 0, type = 0;
   char indicator = 'n';

   do
   {
      cout << "1) Farenheit to Celcius" << endl
         << "2) Celcius to Farenheit" << endl
         << endl << "What do you want to convert? ";

      cin >> type;

      if(type == 1)
      {
         cout << endl << "Enter Temperature in Farenheit: ";
         cin >> f;
         cout << "Temperature: " << (f/1.8) - 32 << " Celcius" << endl;
      }
      else if(type == 2)
      {
         cout << endl << "Enter Temperature in Celcius: ";
         cin >> c;
         cout << "Temperature: " << (1.8*c) + 32 << " Farenheit" << endl;
      }

      cout << "Do you want to enter another value (y or n)? ";
      cin >> indicator;

   } while((indicator=='y' || indicator=='Y'));

   return 0;
}

There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Yoni

I wouldn't multiply floats by ints unless there's a special reason to.

i.e., instead of doing (1.8*c), you're better off doing (9*c)/5.
And instead of (f/1.8), use (5*f)/9.

Sargera

Why do you have such a problem using up-to-date ANSI C++?  :(

Adron

Quote from: Yoni on August 21, 2004, 05:55 PM
I wouldn't multiply floats by ints unless there's a special reason to.

i.e., instead of doing (1.8*c), you're better off doing (9*c)/5.
And instead of (f/1.8), use (5*f)/9.

You made me think of f/2.8. Do you know a good explanation for f/2.8 etc?

BaDDBLooD

Quote from: Sargera on August 21, 2004, 06:11 PM
Why do you have such a problem using up-to-date ANSI C++?  :(

What are you talking about?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Adron

Quote from: BaDDBLooD on August 21, 2004, 06:28 PM
Quote from: Sargera on August 21, 2004, 06:11 PM
Why do you have such a problem using up-to-date ANSI C++?  :(

What are you talking about?

Maybe he wants you to use <iostream> instead of <iostream.h>.

Grok

"You code is bad"
"Your code is worse"

such posts that are not followed by constructive suggestions will be held against the person who posted it.

Kp

Quote from: Grok on August 21, 2004, 06:39 PM"You code is bad"
"Your code is worse"

such posts that are not followed by constructive suggestions will be held against the person who posted it.

Is it considered constructive to inform the original author that his bad code is an inherent fault of the language he has chosen to use, and that he should therefore consider switching immediately to a superior language? :P
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Sargera

Quote from: Adron on August 21, 2004, 06:30 PM
Quote from: BaDDBLooD on August 21, 2004, 06:28 PM
Quote from: Sargera on August 21, 2004, 06:11 PM
Why do you have such a problem using up-to-date ANSI C++?  :(

What are you talking about?

Maybe he wants you to use <iostream> instead of <iostream.h>.

Hmm, I was always told (and thought) that <iostream> was up-to-date on ANSI standards with the usage of the std namespace, as where <iostream.h> was old ANSI C++.