Basic Calculator, help please!
Aug 19, 2013 at 4:24am UTC
Hello! I need some help on this code I currently have for my basic calculator task.
Here is the code, the blanks (___) is what I have troubles on what to put in those spaces:
#include <iostream>
___multiply(int x, int y)
{
_______ x_y;
}
___divide(int x, int y)
{
_______ x_y;
}
___add(int x, int y)
{
_______x_y;
}
___subtract(int x,int y)
{
_______x_y;
}
using namespace std;
___ ____()
{
___op='c':
___x, y;
while(op!='e')
{
cout_"What operation would you like to perform: add (+), subtract (-), divide (/),multiply(*), [e]xit?";
cin_op
switch(op)
{
___ '+':
cin__x;
cin__y;
cout__x__ "+" __y__ "=" __add(x, y)__endl_
break;
_____'-':
cin__x;
cin__y;
cout__x__ "-" __y__ "=" __subtract(x, y)__endl_
break;
_____'/':
cin__x;
cin__y;
cout__x__ "/" __y__ "=" __divide(x, y)__endl_
break;
_____'*':_
cin__x;
cin__y;
cout__x__ "*" __y__ "=" __multiply(x, y)__endl_
break;
_____'e':
_____;
_____:
cout_"Sorry, try again"__endl
}
}
return_;
If someone can help me out here I would really appreciate it. :)
Aug 19, 2013 at 4:48am UTC
lol.
doesn't your reference specify that
operator<<() is used with ostream ?
any way, the first function should be:
1 2 3 4
int multiply( int x , int y )
{
return x * y;
}
complete the remaining functions on your own, move down after the
using
statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#define WHATEVER_TO_COUT "some statement.\n"
int main()
{
std::cout << WHATEVER_TO_COUT ;
char op = NULL;
int x , y;
std::cin >> x >> op >> y;
double result;
switch (op)
{
case '*' :
result = multiply(x,y);
break ;
}
return 0;
}
i dealt with this question like being from a beginner, even though it looks like a prank-ing question.
are you coming from a different language and starting C++ from the bottom ?
Aug 19, 2013 at 7:15am UTC
Thanks for the reply, yeah I'm starting from the bottom with this language. I was doing Visual Basic programs before but C++ is a whole new thing to me.
Okay I got the first part, didn't think it was just a little thing to get it going
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int multiply(int x, int y)
{
return x_y;
}
int divide(int x, int y)
{
return x_y;
}
int add(int x, int y)
{
return x_y;
}
int subtract(int x,int y)
{
return x_y;
}
I'll move down and give the functions after the using statement a crack.
Last edited on Aug 19, 2013 at 7:21am UTC
Aug 19, 2013 at 7:52am UTC
dude, i suggest you go get a reference.
you can't learn programming just like that.
download "C++ Primer (5th edition)- Stanley B. Lippman "
i heard a word around about a 6th edition, maybe it covers the 2011 standard.
Topic archived. No new replies allowed.