By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

New to programming, tried a calculator, help?

P: 1
As above, I'm still trying to figure out the most part, as I have only taken recently interest into picking up programming.
My current code is:


#include <iostream>
using namespace std;

int a, b, sum, c, d, e, f, g, h,

struct database ()
{
string name= add, subtract, multiply, divide;
};

int main ()

{
database calculator;
string name;
cout << "Would you like to (add), subtract),(multiply) or (divide)?";
getline(cin, name);
if (add)=true
cin >> a;
cin >> b;
sum = a+b;
cout << sum << endl;

if else
(subtract)=true
cin >> c;
cin >> d;
sum = c-d;
cout << sum << endl;

if else
(multiply)=true
cin >> e;
cin >> f;
sum = e*f;
cout << sum << endl;

if else
(divide) =true
cin >> g;
cin >> h;
sum = g/h;
cout << sum << endl;
return 0;
}


The basic gist of this thing is a calculator based on what the user wants to do, but I can't figure out a correct way to do it.
Aug 10 '17 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
There are a lot of code errors in the program:

1) all the if statements are not coded correctly
2) the if statements use the = assignment operator instead of the equality operator ==.
3) check your string inside the struct. Display it and see if it contains what you think it does. It's almost like you want to use an array but failed to define an array.
4) the member-of operator is never used even though the value is a member-of the struct.

My suggestion is to start over.

Then code your main like this:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.  
  4. }
Verify this compiles.

Then add code to the program. Not a lot.

Recompile and verify it still compiles.

Then add a little more code...etc.

This way you can see if the code does not compile, the error will be in the last lines you added.

Post again when you get a clean compile.
Aug 11 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.