Thread: A Simple Calculator Program Not Working

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    97

    Angry A Simple Calculator Program Not Working

    hi all. i was making a calculator program last night. i use dev c++ bloodshed, and its really picky on certain things. well, this program isnt working, and i cant seem to find out why. can any of u plz help me?! thx alott..

    btw, i am on a mac computer at school, and have the coding on a floppy. mac isnt lettin me copy n' paste, so i cant do the code]....[/code] statement. srry... and disregard those squares at the start of each line...macs are so dumb!
    Code:
    #pragma hdrstop
    
    #include <iostream.h>
    
    #include <conio.h>
    
    
    
    void main()
    
    {
    
    
    
    int var1
    
    int var2
    
    int var3
    
    int var4
    
    int choice1
    
    int choice2
    
    int Answer1
    
    int Answer2
    
        
    
       do
    
        {
    
        cout << "\nHello, do you want to add or subtract numbers? (a/s)";
    
        cin >> choice1;
    
        
    
          if ( choice1 == 'a' )
    
            {
    
            cout << "\nPlease enter the first number and second number, to be added, seperated by a space: ";
    
            cin >> var1;
    
            cin >> var2;
    
            
    
            Answer1 = var1 + var2
    
            
    
             cout << "\nThe answer is " << Answer1;
    
            }
    
            
    
          if ( choice1 == 's' )
    
            {
    
            cout << "\nPlease enter the first number and second number, to be subtracted, seperated by a space: ";
    
            cin >> var3;
    
            cin >> var4;
    
            
    
            Answer2 = var3 + var4
    
            
    
             cout << "\nThe answer is " << Answer2;
    
            }
    
          
    
            cout << "\nDo you want to do this again? (y/n)";
    
            cin >> choice2;
    
            
    
        }  
    
        while ( choice2 != 'n' )
    
        getch()
    
        
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > copy n' paste, so i cant do the code]....[code]
    Sure you can - just add them in manually afterwards.
    You just managed to type in 11 of the required 13 characters after all

    A woeful lack of ; at the end of way too many lines seems to be the biggest problem
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    liek whcih ones? if doesnt need it, i think. and errors i get are like cout undeclared and var1 undeclared ....errors like that.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Contrast with your previous effort which had too many ;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    24
    void main()
    shouldn't that be
    Code:
     int main(void)

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    can u guys actually tell me where i am wrong? i did notice i forgot the ; after the parts where i was asigning the values for the asnwer1 and 2 variables. ill put those in when i get to my house. where else is sumthin wrong? do i need iostream.h, or iostream? and ill also try the int main(void) command when i get home. thx for ur help so far!

  7. #7
    Registered User
    Join Date
    Jan 2004
    Posts
    24
    im not big on c++ but i think it should be
    Code:
    #include <iostream>
    using namespace std

  8. #8
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    hmmm....ok, i will try that for the header.

  9. #9
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by oobootsy1
    can u guys actually tell me where i am wrong? i did notice i forgot the ; after the parts where i was asigning the values for the asnwer1 and 2 variables. ill put those in when i get to my house. where else is sumthin wrong? do i need iostream.h, or iostream? and ill also try the int main(void) command when i get home. thx for ur help so far!
    You've been given what you did wrong. You need ';' after statements. Without that, you can't compile. Also change void main() to int main().

    Without the program compiling, what kind of answer do you want to "can u guys actually tell me where i am wrong?"
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  10. #10
    Registered User
    Join Date
    Jul 2003
    Posts
    97
    ok, i will try this stuff when i get home. thx alot, ill post back if it dont work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [PAID] Very simple C script - Not working?
    By spadez in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-12-2009, 08:00 AM
  2. Simple program not working, don't know why
    By Bakster in forum C Programming
    Replies: 11
    Last Post: 01-29-2009, 01:56 PM
  3. Replies: 3
    Last Post: 09-12-2005, 09:08 AM
  4. Replies: 5
    Last Post: 02-02-2003, 10:56 AM
  5. simple program not working
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-04-2002, 11:36 PM