Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I am stupid

Name: pieisgood 2008-02-09 13:48

Ok... I have been reading a book on programming and some such and I wanted to make a simple function. I am doing it wrong though.
This won't let me refer to "addition" more than once or else the compiler throws a bitch fit. Why is that?
#include <cstdlib>
#include <iostream>

using namespace std;

int main ()
{
    char MenuA;
    cout << "please enter A for addition: ";
    cin >> MenuA;
    float x, y, aso;
   
    double addition ();
    {
           cout << "please enter the first number to be added: ";
           cin >> x;
           cout << "please enter the second number to be added: ";
           cin >> y;
          
           aso = x + y;
          
           cout << "the solution is: " << aso;
         
          
           }
   
   
    if ( MenuA == 'A')
    {
         addition;
         }
         else if (MenuA != 'A')
         {
              cout << "you must enter A";
              }
  
             
              return 0;
              }

Name: Anonymous 2008-02-09 13:49

>>1
Ok... I have been reading a book on programming and some such
It'd better be called SICP or you're in for some trouble!

Name: Anonymous 2008-02-09 13:53

addition; is a reference, not call.

Name: Anonymous 2008-02-09 13:56

>>3
then how would I call it? or what ever

Name: Anonymous 2008-02-09 13:57

why the fuck didn't you return anything from the addition function and why is it in main?

Name: Anonymous 2008-02-09 13:59

>>5
read the thread subject

Name: Anonymous 2008-02-09 13:59

addition(); or addition(void);
The code looks strange too - Why do you define the function in the middle of main(), and check if (MenuA == 'A') after it?

Name: Anonymous 2008-02-09 14:06

ok a bit better


#include <cstdlib>
#include <iostream>

using namespace std;


double addition(void)
{
float x, y, aso;
       cout << "please enter the first number to be added: ";
           cin >> x;
           cout << "please enter the second number to be added: ";
           cin >> y;
          
           aso = x + y;
          
           cout << "the solution is: " << aso;
           }

int main ()
{
    char MenuA;
    cout << "please enter A for addition: ";
    cin >> MenuA;

   
   
    if ( MenuA == 'A')
    {
         addition();
         }
         else if (MenuA != 'A')
         {
              cout << "you must enter A";
              }
  
             
              return 0;
              }

Name: Anonymous 2008-02-09 14:06

Try reading the book again.

Name: Anonymous 2008-02-09 14:13


double add ()
{
  in: x
  in: y
  return x + y
}

main ()
{
  add ()
}


more like this faggot.

Name: Anonymous 2008-02-09 14:15

woooo now it runs until you don't enter 'y'
 :D
#include <cstdlib>
#include <iostream>

using namespace std;


double addition(void)
{
float x, y, aso;
       cout << "please enter the first number to be added: ";
           cin >> x;
           cout << "please enter the second number to be added: ";
           cin >> y;
          
           aso = x + y;
          
           cout << "the solution is: " << aso << "\n";
          
           }

int main ()
{
char yns;
    char MenuA;
    cout << "please enter A for addition: ";
    cin >> MenuA;

   
   
    if ( MenuA == 'A')
    {
         addition();
         }
         else if (MenuA != 'A')
         {
              cout << "you must enter A";
              }
    cout << "would you like to go again? (y/n): ";
    cin >> yns;
   
    do
    {
        addition();
         cout << "would you like to go again? (y/n): ";
    cin >> yns;
        } while (yns == 'y');
     }

Name: Anonymous 2008-02-09 14:17

>>11
jesus christ learn how to indent, faggot.

Name: Anonymous 2008-02-09 14:20

>>1
Hello and welcome to our community. if/else menus are not elegant and even considered harmful, try to refrain using them and use switch().

Name: Anonymous 2008-02-09 14:22

>>13
Hello and welcome to our community. if/else menus are not elegant and even considered harmful, try to refrain from using them and use switch().

  

Name: Anonymous 2008-02-09 14:28

>>12

#include <cstdlib>
#include <iostream>
using namespace std;
double addition(void)
{float x, y, aso; cout << "please enter the first number to be added: "; cin >> x;
 cout << "please enter the second number to be added: "; cin >> y;
 aso = x + y; cout << "the solution is: " << aso << "\n";}
int main ()
{
char yns;
char MenuA;
cout << "please enter A for addition: "; cin >> MenuA;
if ( MenuA == 'A'){addition();}
else if (MenuA != 'A')
{cout << "you must enter A";}
cout << "would you like to go again? (y/n): "; cin >> yns;
do{ addition(); cout << "would you like to go again? (y/n): "; cin >> yns; } while (yns == 'y');}

Name: Anonymous 2008-02-09 14:29

Stop posting.

Name: Anonymous 2008-02-09 14:40

>>13,14
Produces the exact same compiled code in any modern compiler.

Name: Anonymous 2008-02-09 14:45

>>17
Back to /b/, please.

Name: Anonymous 2008-02-09 15:22

>>17
Switches can be optimized with jump tables, depending on the cases. No modern compiler compiler optimizes if-else

Name: Anonymous 2008-02-09 15:53

I added some functions... but the way I am trying to get the common denominator isn't accurate enough :(

#include <cstdlib>
#include <iostream>
using namespace std;
float addition(void)
{float x, y, aso; cout << "please enter the first number to be added: "; cin >> x;
 cout << "please enter the second number to be added: "; cin >> y;
 aso = x + y; cout << "the solution is: " << aso << "\n";}
float division (void)
{ float x, y, dso;
cout << "please enter the numerator "; cin >> x;
 cout << "please enter the denominator: "; cin >> y;
 dso = x/y; cout << "the solution is: " << dso << "\n";}
float subtraction (void)
{ float x, y, sso;
cout << "please enter the first number to be subtracted: "; cin >> x;
 cout << "please enter the second number to be subtracted: "; cin >> y;
 sso = x - y; cout << "the solution is: " << sso << "\n";}
float multiplication (void)
{ float x, y, mso;
cout << "please enter the first number to be multiplied: "; cin >> x;
 cout << "please enter the second number to be multiplied: "; cin >> y;
 mso = x * y; cout << "the solution is: " << mso << "\n";}
float degrees_to_radians (void)
{float radianst, radiansb;
 int dgrs, cdr;
 cdr = 1;
 cout << "please enter degrees to be converted to radians: " ;
 cin >> dgrs;   
 while (dgrs%cdr == 0 && 180%cdr == 0)
 {cdr++;}
        radianst = dgrs/cdr;
        radiansb = 180/cdr;
        cout << dgrs << "in radians is: " << radianst << "pi/" << radiansb << "\n";
        }
int main ()
{
char yns;
char Menu;
cout << "menu: " << "\n";
cout << "A: Addition\n";
cout << "D: Division\n";
cout << "S: Subtraction\n";
cout << "M: Multiplication\n";
cout << "R: Degrees to radians\n";
cin >> Menu;
switch (Menu)
{
       case 'A':
       addition();
       break;
       case 'D':
       division();
       break;
       case 'S':
       subtraction();
       break;
       case 'M':
       multiplication();
       break;
       case 'R':
       degrees_to_radians();
       break;
       }
       return main();
       }

Name: Anonymous 2008-02-09 16:01

fuck
this

Name: Anonymous 2008-02-09 16:04

HOLY FUCKING SHIT

Seriously, get Emacs, and paste the code in, then hit tab on every line. It will AUTO-INDENT IT FOR YOU.

Name: Anonymous 2008-02-09 16:06

>>22
indentation shouldn't really matter... if it matters that much to you go use python or something you faggot.

Name: Anonymous 2008-02-09 16:21

>>23
I can't read this faggot's code.

Name: Anonymous 2008-02-09 16:25

Which part of `Stop posting' did you not understand?

Name: Anonymous 2008-02-09 16:31

>>25
You're confusing proper.stringQuotes with proper.charQuotes, Sir.

Name: Anonymous 2008-02-09 16:32

>>26
I'm not. Also shitCase is for niggers.

Name: Anonymous 2008-02-09 16:44

if you have no arguments for a function, you need to have void in the parens.

i.e main(void), whatever(void)

Name: Anonymous 2008-02-09 17:08

Fuck off, learn C before Sepples.

Name: Anonymous 2008-02-09 17:29

>>22
Uh, it's emacs. Try C-M-\. Why the FUCK would someone TAB each line?

Name: Anonymous 2008-02-09 19:05

Fuck off, learn C++ before C.

Name: Anonymous 2008-02-09 19:31

Stop posting.

You are stupid.
Your code is shit.
You're not learning anything, because you're stupid. Your code will be shit until you gtfo and become less stupid.

Name: Anonymous 2008-02-09 19:44

This is why you don't learn C or a C-like language as your first programming language.

Name: Anonymous 2008-02-09 20:34

>>30
Because they're scared of hitting ctrl+alt+bksp.

Name: Anonymous 2008-02-09 20:39

>>34
I see what you did there

Name: Anonymous 2008-02-09 23:00

>>35
It's true. I actually did hit CAB once. And I lost a lot of work too. It's a good thing writing Lisp code is just as much fun the second time around. ;_;

Name: Anonymous 2008-02-10 2:40

You realize you can turn off and rebind that key combo?

When I would ever hit shift-alt-meta-super-k, I have no idea, but I know I will NEVER accidentally hit it. Ever.

Name: Anonymous 2008-02-10 2:48

cdr = 1;
cdr

MY OTHER CAR!

Name: Anonymous 2008-02-10 5:24

>>36
Section "ServerFlags"
    Option "DontZap" "true"
EndSection

Name: Anonymous 2009-08-17 0:47

Lain.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List