Valhalla Legends Forums Archive | C/C++ Programming | My First c++ application

AuthorMessageTime
BaDDBLooD
[code]

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

[/code]

Suggestions / Comments Apreciated!
August 21, 2004, 7:15 PM
iago
It's better than Mephisto's :D

<edit> Don't take any of his advice in that thread, please. It's not very good.
August 21, 2004, 7:17 PM
Sargera
[quote author=BaDDBLooD link=board=30;threadid=8286;start=0#msg76582 date=1093115912]
Lmao! wow that is really bad!
[/quote]

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++ :)
August 21, 2004, 7:32 PM
iago
[quote author=Sargera link=board=30;threadid=8286;start=0#msg76584 date=1093116767]
[quote author=BaDDBLooD link=board=30;threadid=8286;start=0#msg76582 date=1093115912]
Lmao! wow that is really bad!
[/quote]

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++ :)
[/quote]

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
August 21, 2004, 7:36 PM
BaDDBLooD
My Second Application:

[code]

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

[/code]
August 21, 2004, 8:23 PM
Sargera
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.
August 21, 2004, 8:32 PM
BaDDBLooD
Eh.. it looks correct in vc++, it fucks up when i use code tags ;O

another program:

[code]

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

[/code]
August 21, 2004, 8:35 PM
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.
August 21, 2004, 10:55 PM
Sargera
Why do you have such a problem using up-to-date ANSI C++? :(
August 21, 2004, 11:11 PM
Adron
[quote author=Yoni link=board=30;threadid=8286;start=0#msg76625 date=1093128916]
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.
[/quote]

You made me think of f/2.8. Do you know a good explanation for f/2.8 etc?
August 21, 2004, 11:18 PM
BaDDBLooD
[quote author=Sargera link=board=30;threadid=8286;start=0#msg76629 date=1093129873]
Why do you have such a problem using up-to-date ANSI C++? :(
[/quote]

What are you talking about?
August 21, 2004, 11:28 PM
Adron
[quote author=BaDDBLooD link=board=30;threadid=8286;start=0#msg76639 date=1093130901]
[quote author=Sargera link=board=30;threadid=8286;start=0#msg76629 date=1093129873]
Why do you have such a problem using up-to-date ANSI C++? :(
[/quote]

What are you talking about?
[/quote]

Maybe he wants you to use <iostream> instead of <iostream.h>.
August 21, 2004, 11:30 PM
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.
August 21, 2004, 11:39 PM
Kp
[quote author=Grok link=board=30;threadid=8286;start=0#msg76645 date=1093131571]"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.[/quote]

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
August 22, 2004, 1:18 AM
Sargera
[quote author=Adron link=board=30;threadid=8286;start=0#msg76641 date=1093131011]
[quote author=BaDDBLooD link=board=30;threadid=8286;start=0#msg76639 date=1093130901]
[quote author=Sargera link=board=30;threadid=8286;start=0#msg76629 date=1093129873]
Why do you have such a problem using up-to-date ANSI C++? :(
[/quote]

What are you talking about?
[/quote]

Maybe he wants you to use <iostream> instead of <iostream.h>.
[/quote]

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++.
August 22, 2004, 3:25 AM
Stwong
I tend to use stdio, but that's just personal preference. Well, thanks to a speed advantage. :P
August 22, 2004, 4:59 AM
Sargera
[quote author=Stwong link=board=30;threadid=8286;start=15#msg76733 date=1093150790]
I tend to use stdio, but that's just personal preference. Well, thanks to a speed advantage. :P
[/quote]

A speed advantage which is in nearly every case irrelevant?
August 22, 2004, 5:00 AM
Arta
[quote author=Sargera link=board=30;threadid=8286;start=15#msg76734 date=1093150856]
irrelevant?
[/quote]

Lies.
August 22, 2004, 6:05 PM
Myndfyr
[quote author=Arta[vL] link=board=30;threadid=8286;start=15#msg76816 date=1093197951]
[quote author=Sargera link=board=30;threadid=8286;start=15#msg76734 date=1093150856]
irrelevant?
[/quote]

Lies.
[/quote]

Would either of you care to clarify what you mean?
August 22, 2004, 7:08 PM
St0rm.iD
sargera is the definition of a troll.
August 22, 2004, 7:35 PM
Adron
[quote author=Sargera link=board=30;threadid=8286;start=15#msg76734 date=1093150856]
[quote author=Stwong link=board=30;threadid=8286;start=15#msg76733 date=1093150790]
I tend to use stdio, but that's just personal preference. Well, thanks to a speed advantage. :P
[/quote]

A speed advantage which is in nearly every case irrelevant?
[/quote]

I think I'd say "in most cases there's no relevant speed advantage to using stdio".
August 22, 2004, 7:45 PM
Grok
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg76844 date=1093203314]
sargera is the definition of a troll.
[/quote]

The above quote is the definition of a personal attack. A name, a label, an intent, and no accompanying on-topic material to cleverly hide that intent.
August 23, 2004, 8:42 AM
Maddox
[quote author=Grok link=board=30;threadid=8286;start=15#msg76977 date=1093250534]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg76844 date=1093203314]
sargera is the definition of a troll.
[/quote]

The above quote is the definition of a personal attack. A name, a label, an intent, and no accompanying on-topic material to cleverly hide that intent.
[/quote]

Just felt like typing something Grok?
August 23, 2004, 9:07 AM
BaDDBLooD
[quote author=Maddox link=board=30;threadid=8286;start=15#msg76978 date=1093252070]
[quote author=Grok link=board=30;threadid=8286;start=15#msg76977 date=1093250534]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg76844 date=1093203314]
sargera is the definition of a troll.
[/quote]

The above quote is the definition of a personal attack. A name, a label, an intent, and no accompanying on-topic material to cleverly hide that intent.
[/quote]

Just felt like typing something Grok?
[/quote]

Actually he was trying to show me about what i should not do. Well that's what i would say anyway!
August 23, 2004, 12:48 PM
Grok
[quote author=Kp link=board=30;threadid=8286;start=0#msg76679 date=1093137481]
[quote author=Grok link=board=30;threadid=8286;start=0#msg76645 date=1093131571]"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.[/quote]

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
[/quote]

Absolutely. Meanwhile, you could suggest how to do it anyway in the language he has chosen. There may be other reasons why someone is stuck with a particular language for the project, so just telling them to switch is not necessarily constructive.
August 23, 2004, 2:03 PM
Grok
[quote author=Maddox link=board=30;threadid=8286;start=15#msg76978 date=1093252070]
[quote author=Grok link=board=30;threadid=8286;start=15#msg76977 date=1093250534]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg76844 date=1093203314]
sargera is the definition of a troll.
[/quote]

The above quote is the definition of a personal attack. A name, a label, an intent, and no accompanying on-topic material to cleverly hide that intent.
[/quote]

Just felt like typing something Grok?
[/quote]

I suggest you do not get into a habit of being a smartass about my moderating.
August 23, 2004, 2:05 PM
St0rm.iD
[me=$t0rm]stops the personal attacks.[/me]
August 23, 2004, 6:03 PM
Myndfyr
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77011 date=1093284214]
[me=$t0rm]stops the personal attacks.[/me]
[/quote]

$t0rm, you stink!
August 23, 2004, 6:46 PM
St0rm.iD
[quote author=MyndFyre link=board=30;threadid=8286;start=15#msg77019 date=1093286783]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77011 date=1093284214]
[me=$t0rm]stops the personal attacks.[/me]
[/quote]

$t0rm, you stink!
[/quote]

myndfyre, youre a microsoft sellout. :-P
August 23, 2004, 7:30 PM
BaDDBLooD
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77026 date=1093289403]
[quote author=MyndFyre link=board=30;threadid=8286;start=15#msg77019 date=1093286783]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77011 date=1093284214]
[me=$t0rm]stops the personal attacks.[/me]
[/quote]

$t0rm, you stink!
[/quote]

myndfyre, youre a microsoft sellout. :-P
[/quote]

[quote]

* $t0rm stops the personal attacks.

[/quote]

rrrrrrriiiiiiggggghhhhhttttt........
August 23, 2004, 8:48 PM
Myndfyr
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77026 date=1093289403]
[quote author=MyndFyre link=board=30;threadid=8286;start=15#msg77019 date=1093286783]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77011 date=1093284214]
[me=$t0rm]stops the personal attacks.[/me]
[/quote]

$t0rm, you stink!
[/quote]

myndfyre, youre a microsoft sellout. :-P
[/quote]

Can you blame me? I can't find a wireless network card that works with Linux. When I tried installing Linux today on my PC, it came close to blowing up (I can't get any kind of GUI whatsoever).
August 23, 2004, 10:14 PM
Adron
[quote author=MyndFyre link=board=30;threadid=8286;start=30#msg77048 date=1093299274]
Can you blame me? I can't find a wireless network card that works with Linux. When I tried installing Linux today on my PC, it came close to blowing up (I can't get any kind of GUI whatsoever).
[/quote]

Did you check this page?
August 23, 2004, 11:17 PM
Newby
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77026 date=1093289403]
[quote author=MyndFyre link=board=30;threadid=8286;start=15#msg77019 date=1093286783]
[quote author=$t0rm link=board=30;threadid=8286;start=15#msg77011 date=1093284214]
[me=$t0rm]stops the personal attacks.[/me]
[/quote]

$t0rm, you stink!
[/quote]

myndfyre, youre a microsoft sellout. :-P
[/quote]
Ooh, BURN.
August 23, 2004, 11:51 PM
Grok
He apparently wants to make lots of money and have a good life, big house, giant yard, wife with big titties and great legs, a home theatre, pool, etc.

I know this to be true because otherwise he would be using Linux.
August 24, 2004, 12:35 AM
St0rm.iD
Grok, you know me, I'm anti-Linux for the desktop, and I think ASP.NET is cool.
August 24, 2004, 3:32 AM
Brandon
[code]#include <iostream.h>

int main()
{

int choice;
float number1;
float 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;
}[/code]

I tried this program out and I noticed that when you divide a smaller number by a bigger number you get 0. I then changed it to "float number1" and "float number2" and I got a more correct result. I don't know if this has been mentioned, but that is just something I found. Even thought this is an old post, you still may care.
September 22, 2004, 10:16 PM
Myndfyr
[quote author=iago link=board=30;threadid=8286;start=0#msg76580 date=1093115841]
<edit> Don't take any of his advice in that thread, please. It's not very good.
[/quote]

My discussion of not recursing the main() function is good! :o

[quote author=Brandon link=board=30;threadid=8286;start=30#msg81451 date=1095891370]
I tried this program out and I noticed that when you divide a smaller number by a bigger number you get 0. I then changed it to "float number1" and "float number2" and I got a more correct result. I don't know if this has been mentioned, but that is just something I found. Even thought this is an old post, you still may care.
[/quote]
It depends on the kind of precision the project requires. When working with floats, you tend to incur an exponentially larger delay in calculation processing. That is, floating-point arithmetic is SLOW SLOW SLOW compared to integer arithmetic.
September 23, 2004, 12:04 AM
Mephisto
[quote author=MyndFyre link=board=30;threadid=8286;start=30#msg81482 date=1095897844]
[quote author=iago link=board=30;threadid=8286;start=0#msg76580 date=1093115841]
<edit> Don't take any of his advice in that thread, please. It's not very good.
[/quote]

My discussion of not recursing the main() function is good! :o

[quote author=Brandon link=board=30;threadid=8286;start=30#msg81451 date=1095891370]
I tried this program out and I noticed that when you divide a smaller number by a bigger number you get 0. I then changed it to "float number1" and "float number2" and I got a more correct result. I don't know if this has been mentioned, but that is just something I found. Even thought this is an old post, you still may care.
[/quote]
It depends on the kind of precision the project requires. When working with floats, you tend to incur an exponentially larger delay in calculation processing. That is, floating-point arithmetic is SLOW SLOW SLOW compared to integer arithmetic.
[/quote]

For a simple calculator application, it shouldn't really matter. :)
September 23, 2004, 4:09 AM
Eibro
[quote]It depends on the kind of precision the project requires. When working with floats, you tend to incur an exponentially larger delay in calculation processing. That is, floating-point arithmetic is SLOW SLOW SLOW compared to integer arithmetic.[/quote]That is incorrect. Perhaps on older processors this was true, but certainly not anymore.
September 23, 2004, 12:39 PM
Myndfyr
[quote author=Eibro[yL] link=board=30;threadid=8286;start=30#msg81552 date=1095943140]
[quote]It depends on the kind of precision the project requires. When working with floats, you tend to incur an exponentially larger delay in calculation processing. That is, floating-point arithmetic is SLOW SLOW SLOW compared to integer arithmetic.[/quote]That is incorrect. Perhaps on older processors this was true, but certainly not anymore.
[/quote]

You're going to tell me that dividing two 8-byte double-precision numbers is the same speed as integer division? Not on your life! One division might not matter, but several million would!
September 24, 2004, 1:09 AM
Eibro
[quote author=MyndFyre link=board=30;threadid=8286;start=30#msg81690 date=1095988164]
[quote author=Eibro[yL] link=board=30;threadid=8286;start=30#msg81552 date=1095943140]
[quote]It depends on the kind of precision the project requires. When working with floats, you tend to incur an exponentially larger delay in calculation processing. That is, floating-point arithmetic is SLOW SLOW SLOW compared to integer arithmetic.[/quote]That is incorrect. Perhaps on older processors this was true, but certainly not anymore.
[/quote]

You're going to tell me that dividing two 8-byte double-precision numbers is the same speed as integer division? Not on your life! One division might not matter, but several million would!
[/quote]It's a comparable speed. Then again, it depends on the processor. On some, floating point arithmetic can actually be faster. In any case, it does not "tend to incur an exponentially larger delay", as you claim.
September 24, 2004, 2:09 AM
Mephisto
In VS.NET 2003 aren't there performance options to enhance performance for integer/floating-point arithmetic? And isn't that implied on optimizations for Pentium 4/AMD processors; I saw an article about it from Microsoft explaining that that particular optimization enhances speed for artihmetic for those processors by using different instructions.
September 24, 2004, 2:18 PM

Search