473,513 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New to programming, tried a calculator, help?

1 New Member
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
1 1544
weaknessforcats
9,208 Recognized Expert Moderator Expert
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

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

Similar topics

0
1397
by: Jason | last post by:
Hello. I would like to create a little asp.net web form that will forecast a calendar date based on a user's input. Here's what the input would be like... 1. Select your product - A drop down of products would go here pulled from an xml file or db. 1 column with the products and the other column with a numeric value pertaining to each
4
1922
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <title>Calculator</title> <script language="Javascript"> <!-- Begin Hiding var total = 0
2
2890
by: boomer | last post by:
Having trouble programming for body mass index. Entering 180 lbs, 72 " ht
3
1833
by: catzid | last post by:
Hi all, I am a total newbie to programming and this is my first posting on a forum, so forgive me if I break any unwritten etiquette about posting. To get to the point I've been using VBA for access to create a tool that will resolve an IP address range using a single network address and the network bit and also convert the results to Hex. I...
2
1318
by: Dalton | last post by:
This is all kind of in another language to, I mean I understand most of the words in relation to programming, but my field of work/study is IT. Anyways, on to the problem. I am working on my 5th project and it is running, just not the way it is supposed to. In the "posting guidelines" section it says not to post the whole source code, but that is...
6
1880
by: mwhit74 | last post by:
here is the code: // CS 200 Lab 11 Problem 3 - phone.cpp // Test program for the keyToTones function. #include <iostream> using namespace::std; // Definition of the PhoneTones struct
3
2879
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of the last operator entered /* Digit entered as integer value i * Updates the value of input accordingly to (input * 10) + i */
1
1627
by: Lamya | last post by:
hi, how can i make a calculator on a C programming?
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.