Need help with a simple program...

This is a discussion on Need help with a simple program... within the C++ Programming forums, part of the General Programming Boards category; hi. i m a new c++ programmer but i have been already programmed vb applications b4... now i m making ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    3

    Question Need help with a simple program...

    hi.
    i m a new c++ programmer but i have been already programmed vb applications b4...
    now i m making a very simple calculator to pracice a bit and i need help.
    the calculator works like that:
    you enter a number
    you select an action
    you enter another number
    you get the resualt
    very very simple as you can c...
    now my problem is that you can c the resualt for 1sec. only and the program is quiting tought i used the command system("PAUSE");...
    here is the source code:

    Code:
    #include <iostream.h>
    
    int main()
    {
     float fnum;
     float snum;
     int action;
     float a;
     cout<<"Enter the first number:"<<endl;
     cin>>fnum;
     cout<<"Select the action:"<<endl;
     cout<<"1. Add (+)"<<endl;
     cout<<"2. Substract (-)"<<endl;
     cout<<"3. Multipyle (*)"<<endl;
     cout<<"4. Divide (/)"<<endl;
     cin>>action;
     cout<<"Enter the second number:"<<endl;
     cin>>snum;
    
     if(action==1)
     {
      a=fnum+snum;
      cout<<"The resualt is: "<<a;
     }
     else if(action==2)
     {
      a=fnum-snum;
      cout<<"The resualt is: "<<a;
     }
     else if(action==3)
     {
      a=fnum*snum;
      cout<<"The resualt is: "<<a;
     }
     else if(action==4)
     {
      a=fnum/snum;
      cout<<"The resualt is: "<<a;
     }
     else
     {
      cout<<"Inviled command."<<endl<<"Quiting program now.";
     }
    
     system("PAUSE");
     return 0;
    }
    can some1 help me here plz?

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    9
    1. Install Visual assist. It has a spell checker which you badly need.
    2. Replace system("PAUSE") with getch(); and #include <conio.h>

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    conio.h is not standard try using cin.get instead or you can just do the smart thing and read this FAQ!!!!
    Woop?

  4. #4
    Banned
    Join Date
    May 2004
    Posts
    55
    If you want to use the function system("PAUSE"); you need to include stdlib.h,
    If you want to use the one im using, getchar(); then u need the cstdio (without .h)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 01:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 05:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

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