Help me!

This is a discussion on Help me! within the C++ Programming forums, part of the General Programming Boards category; I really need some help. First of all, I am new to C++ and I think it's great but for ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    8

    Question Help me!

    I really need some help.
    First of all, I am new to C++ and I think it's great but
    for all the complier errors I get I deserve to die.
    So first of all, I want to know of a good compiler
    that is very simple and it will show me what line the
    error is and perhaps tell me what kind of error it is.

    Second of all, I want to know if this has any errors.
    It's supposed to be calculator program. I made it myself.

    Code:
    #include <iostream.h>
    
    int main()
    
    int mult(int x, int y);
    
    int divi(int x, int y);
    
    int add(int x, int y);
    
    int sub(int x, int y);
    
    int muvi(int x, int y, int z);
    
    int ch;
    
    {
       
       cout<<"Press 1 for multiplication, 2 for division, 3 for addition, 4 for subtraction,5 to multiply then divide: ";
    
       cin>>ch;
    
       if(ch==1)
    
       {   
          
          int x, y;
          
          cout<<"Please input 2 numbers to be multiplied!: ";
          
          cin>>x>>y;
    
          cout<<"Your answer is...drumroll please..."<<mult(x, y)
       
          return 0;
       
       }
    
       int mult(int x, int y);
       
       {
       
          return x*y;
       
       }
       
       else if(ch==2)
       
       {
       
          int x, y;
       
          cout<<"Please input 2 numbers to be divided!: ";
       
          cin>>x>>y;
    
          cout<<"Cutting up your numbers....answer.."<<divi(x, y);
       
          return 0;
       
       }
       
       int divi(int x, int y);
       
       {   
       
          return x/y;
       
       }
    
       else if(ch==3)
    
       {
       
          int x, y;
       
          cout<<"Please input 2 numbers to be added!: ";  
       
          cin>>x>>y;
    
          cout<<"Squishing them together..."<<add(x, y);
       
          return 0;
       }
    
       int add(int x, int y);
    
       {
    
          return x+y;
    
       }
    
       else if(ch==4)
    
       {
    
          int x, y;
    
          cout<<"Please input 2 numbers to be subtracted!: ";
    
          cin>>x>>y;
    
          cout<<"Your answer is"<<sub(x, y);
    
          return 0;
    
       }
    
          int sub(int x, int y);
    
       {
    
          return x-y;
    
       }
    
       else if(ch>=5)
    
       {
       
          int x, y, z;
          
          cout<<"Please input a number, then a number to multiply it by, then 1 more to be divided by: ";
          
          cin>>x>>y>>z;
    
          cout<<"Your answer is"<<muvi(x, y, z);
       
          return 0:;
         
       }
    
          int muvi(int x, int y, int z);
    
       {
    
          return x*y/z;
    
       }
    Thanks in advance!
    By the way, these forums are really convienent!

    This was done with the help of the C++ Tutorials 1-4.
    Last edited by Chib; 12-07-2002 at 01:56 PM.

  2. #2
    Shadow12345
    Guest
    you are forgetting semicolons

    int ch;
    cin>>ch;
    return x*y;

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    I tried Bloodshed Dev and the Borland C++ Compiler 5.5
    What do you mean by putting the variables after main though?
    Don't I need main for it to work?
    Or do you mean like this

    Code:
    #include <iostream.h>
    
    int main()
    
    int divi
    
    int mult //etc etc etc
    Last edited by Chib; 12-07-2002 at 09:48 AM.

  4. #4
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    yep.. put them outside of main like that. then when you need to use them, you do
    Code:
    mult(x, y);
    devi(x,  y);
    add(x, y);
    etc...
    also, you need to remove the semicolons after the if and if else statements. they make them do nothing (because it sees the semicolon as an empty statement, so it executes that, and then does the other block of code anyway).

    hope that made sense...

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    Yeah it made sense, thanks.
    Really great help at this board!

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    I tried compiling this thinking I got pretty much all the bugs
    worked out, I used Bloodshed Dev first, and it wouldn't even
    compile it, then I used the Borland bcc32 and I got this

    Fatal F1003 C:\Borland\BCC55\include\stdcomp.h Error: Must use
    C++ for stdcomp.h

    Anyone know a diffrent compiler I can use or what went wrong?

  7. #7
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    I found a problem!

    Hey I found a problem! The line
    cout<<"Press 1 for multiplication, 2 for division, 3 for addition, 4 for subtraction,5 to multiply then divide: ";
    IS WAY TOO LONG! IT SCROLLED OF THE FORUM PAGE! I HATE SCROLLING HORIZONTALLY!!!
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  8. #8
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    Does anyone know how I can declare a variable like this?

    Code:
    int x
    
    int y
    
    int a=x*y //I want a to be equal to the product of x and y

    I get errors when I do this, or is it just that the compiler that I am using is that CRAPPY!

  9. #9
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    Yeah I got those in the real code but I still get errors...

  10. #10
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    probably because x and y are unitialized. you need to give them values before you assign their values to other variables.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21