Thread: Not sure how to ask this

  1. #16
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by InvariantLoop
    maybe you dont have warning messages turned on. I dont know but on Visual C++, you get a warning error.
    You have an old version of Visual C++ then. 2K3 Toolkit doesn't have that warning message - when no return value is given, the compiler implicitly returns 0.

  2. #17
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Im using Microsoft Visual C++ 6.0 standard edition.
    When no one helps you out. Call google();

  3. #18
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Also, to the OP, you're looking for this, I do believe.

  4. #19
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by InvariantLoop
    Im using Microsoft Visual C++ 6.0 standard edition.
    Yeah, that's pre-standard. Upgrade.

  5. #20
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    It turns out that you don't need to own "The C++ programming language" to get the code for the "Desk Calculator". You might be interested in looking as a learning experience, but obviously I don't recommend turning this in as your project (I'm sure what you've got is fine for the purposes of your class).

    Here is the link:
    http://www.research.att.com/~bs/dc.c
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  6. #21
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Here is how I would do this remeber there is no error checking so you enter a wrong thing to bad
    Code:
    #include <iostream>
    
    int main()
    {
        
        int num1;
        int num2;
        char sign;
        char exitEntry;
        bool exit = false;
        std::cout<<"Welcome to a basic calculator"<<std::endl;
        while(!exit)
        {
            std::cout<<"Enter what calculation you want"<<std::endl;
            std::cin>>num1>>sign>>num2;
            switch(sign)
            {
                case '+':
                    std::cout<<"It equals :"<<num1 + num2<<std::endl;
                    break;
                case '-':
                    std::cout<<"It equals :"<<num1 - num2<<std::endl;
                    break;
                case '/':
                    std::cout<<"It equals :"<<num1 / num2<<std::endl;
                    break;
                case '*':
                    std::cout<<"It equals :"<<num1 * num2<<std::endl;
                case 'e':
                    exit = true;
                    break;
                default:
                    std::cout<<"Invalid operator"<<std::endl;
            }
            std::cout<<"Another y or n? ";
            std::cin>>exitEntry;
            if(exitEntry == 'n')
            {
                exit = true;
            }            
        }
        
        std::cin.get();
        return 0;
    }
    Woop?

  7. #22
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I'm very proub of myself first time I wrote something like this : its all in the mind :P
    Did you ever consider that the poster may be doing an assignment for class?

    In addition, if you have a string of else-if statements, it's supposed to be more efficient to use a 'switch statement', which does the exact same thing as a bunch of else-if statements, so you should familiarize yourself with a switch statement.

  8. #23
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    Thanks for the assistance, I was able to get it based on the information provided. I appreciate it.

    Now, for the next part of this problem...

    It's still the same program, what we're ultimately looking for here is to have the console ask.

    **
    cout << "Continue? ";
    cin >> answer

    **

    answer will be a char value that only accepts y Y n or N as a valid value. If a y or Y is typed in it will then ask the equasion, and it will obviously exit if a n or N is entered.

    **

    cout << "Enter equasion: ";
    cin >> num1 >> opcode >> num2

    **

    This all suppose to be done somehow with functions, I've got some ideas but I'm not sure how to do it.

  9. #24
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    Quote Originally Posted by 7stud
    Did you ever consider that the poster may be doing an assignment for class?

    In addition, if you have a string of else-if statements, it's supposed to be more efficient to use a 'switch statement', which does the exact same thing as a bunch of else-if statements, so you should familiarize yourself with a switch statement.
    Class? Yes. For a grade? No. No grades in this class.

  10. #25
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    I guess you didnt read the code prog-bman posted.
    When no one helps you out. Call google();

  11. #26
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    Quote Originally Posted by InvariantLoop
    I guess you didnt read the code prog-bman posted.
    I did but you have to understand that he's giving me coding options for code we haven't gotten to in the class yet. It works just peachy but the instructor will go "Where the hell did you learn this at?"

    Code:
    #include <iostream>
    using namespace std;
    
    int doEquasion();
    int main()
    {
    	char cont;
    
    	cout << "Continue? ";
    	cin >> cont;
    
    	while(cont == 'y' || cont == 'Y')
    		doEquasion();
    }
    
    doEquasion()
    {
    	int num1, num2, answer;
    	char opcode;
    	cout << "Enter Equasion: ";
    	cin >> num1 >> opcode >> num2;
    
    	if (opcode == '+')
    	{
    		answer = num1 + num2;
    		cout << answer << endl;
    	}
    	else if (opcode == '-')
    	{
            answer = num1 - num2;
    		cout << answer << endl;
    	}
    	else if (opcode == '*')
    	{
    		answer = num1 * num2;
    		cout << answer << endl;
    	}
    	else if (opcode == '/')
    	{
    		answer = num1 / num2;
    		cout << answer<< endl;
    	}
    	else
    		cout << "Invalid Operator\n";
    			
    	char cont;
    	cout << "Continue? ";
    	cin >> cont;
    
    	return answer;
    }
    This sort of works, it lets me do what I want the only problem I have is that it doesn't exit on the "Continue" when I type n or any other letter.
    Last edited by jcmhex; 03-10-2005 at 09:21 AM.

  12. #27
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>it doesn't exit on the "Continue" when I type n or any other letter.
    The problem is simply that you're asking "Continue?" in doEquasion() (it's spelled 'equation' ), while the loop that you're trying to break is in main(). Although the 2 variables are named the same ('cont') in both functions, they are NOT the same, so the 'cont' in main() will never change. The simplest solution I can think of is just to put the prompt for continue in the while loop instead of inside doEquasion(). I have to go right now, but if what I just said doesn't make much sense to you, then just ask
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #28
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    equation

Popular pages Recent additions subscribe to a feed