Buckys C++ Programming Tutorials – 5 – Creating a Basic Calculator

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

46 responses to “Buckys C++ Programming Tutorials – 5 – Creating a Basic Calculator”

  1. scott22v Avatar

    Exactly what i needed. I had to make a tuition calculator for class. Great video thank you

  2. Jay the Novice Gamer Avatar

    I was using Notepad ++ and for some reason I set it to Java and I just realized it after the entire video was over.

  3. Ralakus Avatar

    Here is my "Basic" calculator:

    #include <string>
    #include <iostream>
    #include <math.h>

    int calc(int in1, int in2, int mode);

    int main() {
    int var1(0), var2(0), output(0), mode(1);
    std::string pInput;
    std::cout << "What tpye of operation?n";
    std::cout << " 1) Additionn 2) Subtractionn 3) Multiplicationn 4) Divisionn 5) Powern ";
    bool proceed(false);
    while (!proceed) {
    std::getline(std::cin, pInput);
    if (pInput == "1") {
    mode = 1;
    proceed = true;
    }
    else if (pInput == "2") {
    mode = 2;
    proceed = true;
    }
    else if (pInput == "3") {
    mode = 3;
    proceed = true;
    }
    else if (pInput == "4") {
    mode = 4;
    proceed = true;
    }
    else if (pInput == "5") {
    mode = 5;
    proceed = true;
    }
    else {
    std::cout << "Enter one of the above options in number form: ";
    proceed = false;
    }
    }
    proceed = false;
    std::cout << "Enter the first number: ";
    while (!proceed) {
    std::getline(std::cin, pInput);
    try {
    var1 = std::stoi(pInput);
    proceed = true;
    }
    catch (…) {
    std::cout << "nEnter a number:";
    proceed = false;
    }
    }
    proceed = false;
    std::cout << "Enter the second number: ";
    while (!proceed) {
    std::getline(std::cin, pInput);
    try {
    var2 = std::stoi(pInput);
    proceed = true;
    }
    catch (…) {
    std::cout << "Enter a number";
    proceed = false;
    }
    }
    output = calc(var1, var2, mode);
    std::cout << "nThe answer is " << output << "n";
    std::system("Pause");
    return 0;
    }

    int calc(int in1, int in2, int mode) {
    switch (mode) {
    default: { std::cout << "Errorn";
    return 0;
    }
    case 1: return in1 + in2;
    case 2: return in1 – in2;
    case 3: return in1*in2;
    case 4: return in1 / in2;
    case 5: return pow(in1, in2);
    }
    }
    //On the second thought this isn't so basic

  4. Frankie Tian Avatar

    I coded exactly same expression in IDE and later on i tried to run it , it says : "expected declaration before '}' token". I have double checked every words I typed, nothing wrong, but it just showed ''expected declaration before '}' token". What should I do?

  5. Vlad Modenegro Avatar

    cout << "thanks for help"; ))))))))))

  6. NumanBaran! Avatar

    Oh my god I learned it! I learned about Variables! Subs Likes

  7. miodrag miodrag Avatar

    If i write 12/0 it not works what to do

  8. William Braddell Avatar

    Thank you so much. I've just started an IT degree and have been freaking out over the learning curve but your videos are so helpful.

  9. John Brown Avatar

    You know come to think about it. I am learning c++ as a serious hobby not to pass a silly exam; and it's not necessary for me to know the fancy name the two less than signs in order to make programs of any calibre. My point is that alot of times schools forcefully fill up your head with rubbish that you really don't need.

  10. John Brown Avatar

    This seems to be a randomizing course of videos. I think it would have been better to teach all of the types of variables first. But this is freemium after all.

  11. Ice Cube Avatar

    pretty cool huh ( ͡° ͜ʖ ͡°)

  12. Kitinpáncél Avatar

    Ive been programming for a year, and my hardest code so far was indeed a calculator, which worked with extremely large numbers too.

  13. achraf affes Avatar

    I'm a beginner here , and to make cout and cin easier to remember , think about as "console out" (cout) and "console in" (cin) …

  14. Arthur VIPAUTO Avatar

    Any idea why my code block will randomly stop allowing me to run a build? the green arrow and gear will just turn grey.

  15. Mertiy Avatar

    int main()
    {
    int a;
    int b;
    int c;

    cout << "Enter a number you piece of shit.n";

    cin >> a;

    cout << "Now another number you excuse of a person.n";

    cin >> b;

    c = a + b;

    cout << "Sum of these two are probably not " << 5 << ". Now you can go fuck yourself." << endl;

    return 0;
    }

  16. Luka Reeson Avatar

    Great tutorial. Plain and simple. I wanted to make this basic calc. code as an function. After a few tries, I did it. Here's the code:
    #include <iostream>

    using namespace std;
    int calc();

    int main() {
    cout << "the sum is: " << calc() << endl;

    system("pause");
    return 0;

    }
    int calc() {
    cout << "enter a number: ";
    int a;
    cin >> a;

    cout << "enter another number: ";
    int b;
    cin >> b;

    int sum = a + b;
    return sum;
    }

  17. Aashish goyal Avatar

    it doesnt work when the number is really big, like 21365118732173.

  18. Don't Click The Cookie. Avatar

    Holy crap i feel i'm a programmer now 😀

  19. Protocol 90 Avatar

    You're actually really funny xD

  20. ZzZzZzZ zZzZzZzZz Avatar

    i tried this with product
    but i screwed something up because i didnt get 4*5=20
    i got lik 4550540450

  21. Joleon Morcilla Avatar

    andadaya niyo naman.., may mga basic knowledge na kayo i

  22. Professor Nizar Avatar

    the way you explain this lesson is quite good.
    Thanks

  23. Michael Darby Avatar

    What does hoss mean?

  24. Michael Darby Avatar

    Type in the word awesome while watching this video.

  25. Jonas Lasater Avatar

    why cant i get past the first cout and cin

  26. Prodiigy • Avatar

    My calculator

    #include <iostream>
    Using namespace std;

    Int a;
    Int b;
    Int sum;

    Cout <<"this is a calculator! n;

    Cout << "enter a number. n;

    Cin >> a;

    Int main( )
    {
    Cout << "DJ Khaled: another one. n;

    Cin >> b;

    Sum = a * b;
    }

    Return 0;

  27. Unknown Account Avatar

    My version of it:

    #include <iostream>

    using namespace std;

    int main()
    {

    int first = 0, second = 0, together = 0, choose = 0, temp = 0;

    cout << "1.Add" << endl;
    cout << "2.Subtract" << endl;
    cout << "3.Multiply" << endl;
    cout << "4.Divide" << endl;
    cin >> choose;

    switch(choose){

    case 1:
    cout << "Enter Your Numbers:" << endl;
    cin >> first;
    cin >> second;
    together = first + second;
    cout << "The Answer is:" << together << endl;
    break;
    case 2:
    cout << "Enter Your Numbers:" << endl;
    cin >> first;
    cin >> second;

    if(second > first){
    temp = first;
    first = second;
    second = temp;
    }

    together = first – second;
    cout << "The Answer is:" << together << endl;
    break;
    case 3:
    cout << "Enter Your Numbers" << endl;
    cin >> first;
    cin >> second;
    together = first * second;
    cout << "The Answer is:" << together << endl;
    break;
    case 4:
    cout << "Enter Your Numbers:" << endl;
    cin >> first;
    cin >> second;

    if(second > first){
    temp = first;
    first = second;
    second = temp;
    }

    together = first / second;
    cout << "The Answer is:" << together << endl;
    break;
    default :
    cout << "anERROR:Invalid Input" << endl; /* Need to learn how to clear the input buffer here */
    break;
    }

    return 0;
    }

  28. Im Parzelli Avatar

    I guess i dont even have to go to college?? wow this is incredible thankyou so much, you should of saw the smile on my face when i made my own friggn calculator program wtf (in a good way)

  29. Niggy McNig Avatar

    I'm coming back here from tutorial 12 because i tried to do this again without the tutorial and i couldn't remember where to start! I remember how to do variables and cout, cin, all that stuff but i just couldn't create it without watching this again 🙁

    Is this normal?? I feel like im not learning enough :/

  30. Gaming Turkey Avatar

    Test ride my calculator! I made it so the user can choose the operation (And yes, I'm crossing over from C):

    #include <iostream>
    #include <stdio.h>

    using namespace std;

    int a, b;
    char operation;

    int main()
    {
    cout << "Enter a numbern";
    cin >> a;

    cout << "Enter another numbern";
    cin >> b;

    instruct:
    cout << "nWhich arithmetic operation do you want to use between the two numbers?n'A' for additionn'S' for
    subtructionn'M' for multiplicationn'D' for divisionnn";
    cin >> operation;

    switch (operation)
    {
    case 'A' : case 'a' : cout << "n" << a+b << endl; break;
    case 'S' : case 's' : cout << "n" << a-b << endl; break;
    case 'M' : case 'm' : cout << "n" << a*b << endl; break;
    case 'D' : case 'd' : cout << "n" << (float)a/(float)b << endl; break;
    default : cout << "nYou did not follow the instructionn"; goto instruct;
    }

    return 0;
    }

  31. Ishan Kumar Avatar

    Can someone please tell me why did we write sum a second time in line 18
    "<< sum << endl; "
    here^
    Thank you.

  32. Dean Toonen Avatar

    i got a small question, If i want a space inbetween the last awnser and the next question, where can i add another endl; or n

    I tried putting it behind the variables so i had like
    cin >> b; endl;

    However this didnt exactly work out. would i have to add it infront of the next rule?

    endl << cout << ''Enter a number n'';?

  33. Yannay gan eden Avatar

    you are my hero ! thank you

  34. Shashwat Dahal Avatar

    When I run from the codeblock , it executes fine but when I go to the directory of my program located on bin folder i open it and i wrote the first number on calculator and second number after that it does not show the result…. i rebuilt that project for couple of times it runs fine from codeblock but when i launch it manually it quits on result without showing can anyone answer me?

  35. Vishal kumar Avatar

    Trust me! you are amazing

  36. Prodiigy • Avatar

    #include <iostream>

    Using namespace std;

    int a;
    int b;
    int sum;

    cout << "enter a number b0use n";

    cin >> a;

    cout << "enter another to become my sex slave n";

    cin >> b;

    sum = a – b;

    cout << the sum is << sum << endl

  37. Toshko Jovanov Avatar

    #include <iostream>

    using namespace std;

    int main()
    {
    int a;
    int b;
    int sum;
    cin >> a;
    cin >> b;
    sum = a + b;
    cout << sum << endl;
    }
    or like this 🙂

  38. jishnu das Avatar

    I made a program which calculates the final velocity of an object given its initial velocity, acceleration and time taken

  39. Haikal Academy Avatar

    hallo Bucky what happen if i write it like this?

    int a;
    int b;

    Int sum = a + b;

    cout <<"enter a Number" << endl;
    cin>>a;

    cout <<"enter another number" << endl;
    cin >> b;

    cout << "the sum of the numbers are " << sum << endl;

    i mean to write variable ( int sum) at the beggining of the Statement?

  40. surviving gamer Avatar

    I made a calculator myself 😀 It shows a + b = c

    #include <iostream>using namespace std;int main()
    {    int a;
        int b;
        int c;
        cout << "Enter a number" << endl;
        cin >> a;    cout << "enter another number n";
        cin >> b;
        c = a + b;
        cout << a;
        cout << " + ";
        cout << b;
        cout << " = ";
        cout << c;  return 0;
    }

  41. Joon X Avatar

    Thank you teacher bucky …

  42. Rahol Saha Avatar

    what if we dont write endl?? as the code still working

  43. Shuyanchi Avatar

    what does "hoss" mean?

  44. Nenad Bogoevski Avatar

    Who wrote huge numbers to see if the calculator is going to give you the result

Leave a Reply

Your email address will not be published. Required fields are marked *