[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Buckys C++ Programming Tutorials – 5 – Creating a Basic Calculator
by
Tags:
Comments
46 responses to “Buckys C++ Programming Tutorials – 5 – Creating a Basic Calculator”
-
Exactly what i needed. I had to make a tuition calculator for class. Great video thank you
-
I was using Notepad ++ and for some reason I set it to Java and I just realized it after the entire video was over.
-
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 -
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?
-
cout << "thanks for help"; ))))))))))
-
Oh my god I learned it! I learned about Variables! Subs Likes
-
If i write 12/0 it not works what to do
-
holy crap yes
-
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.
-
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.
-
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.
-
pretty cool huh ( ͡° ͜ʖ ͡°)
-
Ive been programming for a year, and my hardest code so far was indeed a calculator, which worked with extremely large numbers too.
-
I'm a beginner here , and to make cout and cin easier to remember , think about as "console out" (cout) and "console in" (cin) …
-
Any idea why my code block will randomly stop allowing me to run a build? the green arrow and gear will just turn grey.
-
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;
} -
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;
} -
it doesnt work when the number is really big, like 21365118732173.
-
Holy crap i feel i'm a programmer now 😀
-
You're actually really funny xD
-
i tried this with product
but i screwed something up because i didnt get 4*5=20
i got lik 4550540450 -
andadaya niyo naman.., may mga basic knowledge na kayo i
-
the way you explain this lesson is quite good.
Thanks -
What does hoss mean?
-
Type in the word awesome while watching this video.
-
why cant i get past the first cout and cin
-
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;
-
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;
} -
pretty cool huh
-
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)
-
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 :/
-
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;
} -
Can someone please tell me why did we write sum a second time in line 18
"<< sum << endl; "
here^
Thank you. -
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'';?
-
you are my hero ! thank you
-
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?
-
Trust me! you are amazing
-
#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
-
#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 🙂 -
I made a program which calculates the final velocity of an object given its initial velocity, acceleration and time taken
-
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?
-
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;
} -
Thank you teacher bucky …
-
what if we dont write endl?? as the code still working
-
what does "hoss" mean?
-
Who wrote huge numbers to see if the calculator is going to give you the result
Leave a Reply