file access auditing
+ Reply to Thread
Results 1 to 4 of 4

Thread: C++ problem

  1. #1
    minaadel1994 Guest

    C++ problem

    hi , i have got a problem with this calculator , why when i cant calculate twice.... or more , it automaticly closes help plz heres the code:

    //here it starts
    #include <iostream>
    using namespace std;
    int subs (int x, int y);
    int add (int x, int y);
    int divi (int x, int y);
    int mult (int x, int y);
    int main()
    {
    int x;
    int y;
    cout<<"please input a number then press space and the other number to calculate: \n";
    cin>>x>>y;
    cin.ignore();
    cout<<"equals (substracted) : "<< subs (x,y)<<"\n";
    cout<<"equals (added) : "<< add (x,y)<<"\n";
    cout<<"equals: (divied) : "<< divi (x,y)<<"\n";
    cout<<"equalsmultiplyed) : "<< mult (x,y)<<"\n";
    cin.get();
    }
    int subs (int x, int y)
    {
    return x - y;
    return 0;
    }
    int add (int x, int y)
    {
    return x + y;
    return 0;
    }
    int divi (int x, int y)
    {
    return x / y;
    return 0;
    }
    int mult (int x, int y)
    {
    return x * y;
    return 0;
    }
    // ends here
    now wots wrong?? or wot should i add to prevent it from automaticly closing itself

  2. #2
    Join Date
    Sep 2006
    Posts
    1,649
    You need to use a loop, such as a while() loop to keep the programming going.

    Also, why are you ending all your math functions with
    [PHP]return 0; [/PHP]
    If I recall correctly, that terminates the program doesn't it? If you want your program to keep going I would take off those return 0; statements. Even if those aren't a problem, I still don't understand why you are putting them there.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  3. #3
    minaadel1994 Guest

    i found the fix

    its nothing about cin.ignore(); or return 0; , its about looping , i forgot to loop around the code its suppose to be do { the code } while (*); that makes it loop and it worked peeps ive learned that from a professional programer but thx for helping , by the way cin.ignore(); ignores any error when u loop cuz if it doesn't the program starts redoing the code inf times unless u close it thx it should be :
    #include <iostream>
    using namespace std;
    int subs (int x, int y);
    int add (int x, int y);
    int divi (int x, int y);
    int mult (int x, int y);
    int main()
    {
    int x;
    int y;
    do { //the other fix
    cout<<"please input a number then press space and the other number to calculate: \n";
    cin>>x>>y;
    cin.ignore();
    cout<<"equals (substracted) : "<< subs (x,y)<<"\n";
    cout<<"equals (added) : "<< add (x,y)<<"\n";
    cout<<"equals: (divied) : "<< divi (x,y)<<"\n";
    cout<<"equalsmultiplyed) : "<< mult (x,y)<<"\n";
    } while (*); //the fix
    }
    int subs (int x, int y)
    {
    return x - y;
    return 0;
    }
    int add (int x, int y)
    {
    return x + y;
    return 0;
    }
    int divi (int x, int y)
    {
    return x / y;
    return 0;
    }
    int mult (int x, int y)
    {
    return x * y;
    return 0;
    }
    Last edited by minaadel1994; 07-27-2008 at 06:22 PM.

  4. #4
    Join Date
    Sep 2006
    Posts
    1,649
    Please use code tags when posting code, thanks
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

+ Reply to Thread

Similar Threads

  1. problem
    By minaaaa in forum General discussion
    Replies: 3
    Last Post: 05-11-2013, 06:37 AM
  2. Problem In C++
    By Vipul Motiwala in forum Programming
    Replies: 7
    Last Post: 01-15-2007, 11:14 AM
  3. I got a problem
    By Gabriel in forum Security & Encryption
    Replies: 2
    Last Post: 09-01-2006, 06:41 PM
  4. Problem...
    By liquinn in forum Internet Privacy
    Replies: 2
    Last Post: 08-04-2006, 01:28 PM
  5. another msn problem
    By Unregistered in forum Viruses and Trojans
    Replies: 4
    Last Post: 06-11-2004, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts