Jump to content

Simple C++ code examples.


Heretic121

Recommended Posts

Is C++ code when your hot teacher tells you that you only have a C , but if you diddle her after school, you might get a C++?

 

*sighs*

 

201127233535_TripleFacepalm.jpg

  • Like 1
Link to comment
Share on other sites

Is C++ code when your hot teacher tells you, with a wink and a gleam in her eye, that you only have a C , but if you diddle her after school, you might get a C++?

Soul, I know that you are going back to school and as a friend and fellow FA member, I highly, highly encourage you to NOT do this. Okay? :)

  • Like 1
Link to comment
Share on other sites

Is C++ code when your hot teacher tells you, with a wink and a gleam in her eye, that you only have a C , but if you diddle her after school, you might get a C++?

This :D hahaha

Link to comment
Share on other sites

Gotta get ahead somehow, darnit!

 

Work your ass off :P Oh wait... that was the problem in the first place. Just work... hard? Damn it, Soul!

Link to comment
Share on other sites

Ok, fine... I'll "work it" very hard.......I got moves like Jagger :)

 

Of course you have... ....

...

 

 

Wait... how did we get so horribly off topic?

Link to comment
Share on other sites

See? This is why we can never have anything nice! You guys just thread hijacking all over the place.

Link to comment
Share on other sites

Okay this is the start Heretic- IDK what the errors are, but I'll look at it after dinner.

#include <iostream>

int main()
{
    double num1;
    char op;
    double num2;
    int pick;
    double answer;


    {
        std::cout << "Please enter your first number.\n";
        std::cin >> num1
        std::cout << "Please enter your second number.\n";
        std::cin >> num2

        std::cout << "Do you wish to add << "+" >> these numbers?\n";
        std::cout << "Press y to add numbers or n to leave program.\n";

        std::cin >> pick
    }
        if (pick == y)
        {
            answer = num1 + num2;
            std::cout << num1 << "+" << num2 "=" << answer << std::endl;
        }
        if (pick == n)
        {
            return 0;
        }



Link to comment
Share on other sites

Okay second try after a fresh look. LOL!

#include <iostream>

int main()
{

    double num1;
    char op;
    double num2;
    int pick;
    double answer;


    {
        std::cout << "Please enter your first number.\n";
        std::cin >> num1;
        std::cout << "Please enter your second number.\n";
        std::cin >> num2;

        std::cout << "Please enter the operator you wish to use, choices +.\n";
        std::cin >> op;

        if (op == '+')
        {
            answer = num1 + num2;
            std::cout << num1 << "+" << num2 << "=" << answer << std::endl;
        }
    }
        std::cout << "Press '1' to restart the program or '0' to quit. \n";
        std::cin >> pick;

        if(pick == 1)
        {
            main ();
        }
        if(pick == 0)
        {
            return 0;
        }
}


Link to comment
Share on other sites

Okay here I was going for the loop, but after entering either y or n it closes the program. Hmmph!

#include <iostream>

int main()
{

    float Num1;
    float Num2;
    float Answer;

    int which_calculation;

    char again = 'y';

    {
        std::cout << "Press 1 to add.\n";
        std::cin >> which_calculation;

        std::cout << "Please enter your first number.\n";
        std::cin >> Num1;
        std::cout << "Please enter your second number.\n";
        std::cin >> Num2;
    }
        if (which_calculation == 1)
        {
            Answer = Num1 + Num2;
        }

    std::cout << "The answer is ...\n";
    std::cout << Answer << std::endl;

    if (again == 'y')
    {
        std::cout << "again (y/n)?";
        std::cin >> again;
    }
}




Link to comment
Share on other sites

Little confused about the parenthesis on line 14 & 22 lol

 

Also, you're not getting the user input for "answer" :P

So "answer" is constantly "y"

  • Like 1
Link to comment
Share on other sites

Yes that is the issue that I was getting. It was driving me nuts. Also when I used while, it would ask me the same question or exit, can't remember which. But if I used n it would restart the process. Help me oh great one.

 

Originally I had

if (again == 'y')
    {
        std::cout << "again (y/n)?";
        std::cin >> again;
    }

before the rest of the script and it would just endlessly ask you if you wanted to do it again. 
Therefore I moved.

 

Which lines are you talking about?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.