I am at work and did this program on notepad and not sure if this is correct or not. Can someone that has the visual studio compiler test this and let me know if it works. If it does no could you offer any minor feedback on the location of the errors since I am not able to debug it.

//Programmed by: JIm Johnson
//Date: 3-23-2009
//Assignment: In class assignment

class Arithmetic

{
public:
	int Add(int num1, int num2);
	int Subtract(int num1, int num2);
	int Multiply(int num1, int num2);

private:
	int addedTota, subtractedTotal, multipliedTotal;

};

//Adding the two numbers together
int Add(int num1, int num2)
{
	int addedTotal;
	addedTotal = num1 + num2;
	cout << "The two numbers added together are: ";
	cin >> addedTotal;
	return addedTotal;
}

//Subtracting the two numbers together
int Subtract(int num1, int num2)
{
	int subtractedTotal;
	subtractedTotal = num1 - num2;
	cout << "Subtracting the first and second number give a difference of: ";
	cin >> subtractedTotal;
	return subtractedTotal;
}

//Multiplying the two numbers together
int Multiply(int num1, int num2)
{
	int multipliedTotal;
	multipliedTotal = num1 * num2;
	cout << "Numbers 1 and 2 multiplied together give a product of: ";
	cin >> multipliedTotal;
	return multipliedTotal;
}	
	 
int main()
{
	cout << "Enter the first number: ";
	cin >> num1;
	cout << "Enter the second number: ";
	cin >> num2;
	Add(num1, num2);
	Subtract(num1, num2);
	Multiply(num1, num2);
}

Recommended Answers

All 7 Replies

As long as you have an internet connection, you can always check online, whether or not your code compiles. Below are couple links:
Comeau
and
DINKUMWARE

forgot to put in the includes and namespace

//Programmed by: JIm Johnson
//Date: 3-23-2009
//Assignment: In class assignment

#include<iostream>
#inlude<string>

using namespace std;


class Arithmetic

{
public:
	int Add(int num1, int num2);
	int Subtract(int num1, int num2);
	int Multiply(int num1, int num2);

private:
	int addedTota, subtractedTotal, multipliedTotal;

};

//Adding the two numbers together
int Add(int num1, int num2)
{
	int addedTotal;
	addedTotal = num1 + num2;
	cout << "The two numbers added together are: ";
	cin >> addedTotal;
	return addedTotal;
}

//Subtracting the two numbers together
int Subtract(int num1, int num2)
{
	int subtractedTotal;
	subtractedTotal = num1 - num2;
	cout << "Subtracting the first and second number give a difference of: ";
	cin >> subtractedTotal;
	return subtractedTotal;
}

//Multiplying the two numbers together
int Multiply(int num1, int num2)
{
	int multipliedTotal;
	multipliedTotal = num1 * num2;
	cout << "Numbers 1 and 2 multiplied together give a product of: ";
	cin >> multipliedTotal;
	return multipliedTotal;
}	
	 
int main()
{
	cout << "Enter the first number: ";
	cin >> num1;
	cout << "Enter the second number: ";
	cin >> num2;
	Add(num1, num2);
	Subtract(num1, num2);
	Multiply(num1, num2);
}

Some comments ...

//Adding the two numbers together
int Add(int num1, int num2)
{
	int addedTotal;
// sum up the values ...
	addedTotal = num1 + num2;
// display text ...
	cout << "The two numbers added together are: ";
// get the value from user ... why?
	cin >> addedTotal;
// return the value gotten from user ...
	return addedTotal;
}

I found a test compiler and these are the errors I get...

"ComeauTest.c", line 56: error: identifier "Add" is undefined
Add(num1, num2);
^

"ComeauTest.c", line 57: error: identifier "Subtract" is undefined
Subtract(num1, num2);
^

"ComeauTest.c", line 58: error: identifier "Multiply" is undefined
Multiply(num1, num2);


I am fairly new to making functions with Arithmetic::
so if anyone can help me I think this is where my problem lies...

#include<iostream>
#include<string>

using namespace std;

class Arithmetic

{
public:
	int Add(int num1, int num2);
	int Subtract(int num1, int num2);
	int Multiply(int num1, int num2);

private:
	int addedTotal, subtractedTotal, multipliedTotal;

};

//Adding the two numbers together
int Arithmetic::Add(int num1, int num2)
{
	int addedTotal;
	addedTotal = num1 + num2;
	cout << "The two numbers added together are: ";
	cin >> addedTotal;
	return addedTotal;
}

//Subtracting the two numbers together
int Arithmetic::Subtract(int num1, int num2)
{
	int subtractedTotal;
	subtractedTotal = num1 - num2;
	cout << "Subtracting the first and second number give a difference of: ";
	cin >> subtractedTotal;
	return subtractedTotal;
}

//Multiplying the two numbers together
int Arithmetic::Multiply(int num1, int num2)
{
	int multipliedTotal;
	multipliedTotal = num1 * num2;
	cout << "Numbers 1 and 2 multiplied together give a product of: ";
	cin >> multipliedTotal;
	return multipliedTotal;
}	
	 
int main()
{
	int num1, num2;
	cout << "Enter the first number: ";
	cin >> num1;
	cout << "Enter the second number: ";
	cin >> num2;
	Add(num1, num2);
	Subtract(num1, num2);
	Multiply(num1, num2);
}

This compiled successfully but I am not able to see if it linked correctly...can someone with visual studio test this out for me and see if it came back successful or not...

#include<iostream>
#include<string>

using namespace std;

class Arithmetic

{
public:
	int Add(int num1, int num2);
	int Subtract(int num1, int num2);
	int Multiply(int num1, int num2);

private:
	int addedTotal, subtractedTotal, multipliedTotal;

};

//Adding the two numbers together
int Add(int num1, int num2)
{
	int addedTotal;
	addedTotal = num1 + num2;
	cout << "The two numbers added together are: ";
	cin >> addedTotal;
	return addedTotal;
}

//Subtracting the two numbers together
int Subtract(int num1, int num2)
{
	int subtractedTotal;
	subtractedTotal = num1 - num2;
	cout << "Subtracting the first and second number give a difference of: ";
	cin >> subtractedTotal;
	return subtractedTotal;
}

//Multiplying the two numbers together
int Multiply(int num1, int num2)
{
	int multipliedTotal;
	multipliedTotal = num1 * num2;
	cout << "Numbers 1 and 2 multiplied together give a product of: ";
	cin >> multipliedTotal;
	return multipliedTotal;
}	
	 
int main()
{
	int num1, num2;
	cout << "Enter the first number: ";
	cin >> num1;
	cout << "Enter the second number: ";
	cin >> num2;
	Add(num1, num2);
	Subtract(num1, num2);
	Multiply(num1, num2);
}

This compiled successfully but I am not able to see if it linked correctly...can someone with visual studio test this out for me and see if it came back successful or not...

You can't program without a compiler. It's a waste of time. Programming is all about trial and error and you can't do that without a compiler. You'll compile and recompile dozens of times, even with a short program like this. You're better off waiting till you have access to a compiler.

There's only one file, so no linking is required, I don't think, so I don't know how it compiled for you. It didn't compile for me and the reason is that the program has no idea that you are referring to the Arithmetic class when you are calling the Add, Subtract, and Multiply functions (see red). You need to create an Arithmetic object and have it access the functions:

Arithmetic arith;
// code
arith.Multiply (5, 3);
int main()
{
	int num1, num2;
	cout << "Enter the first number: ";
	cin >> num1;
	cout << "Enter the second number: ";
	cin >> num2;
	Add(num1, num2);
	Subtract(num1, num2);
	Multiply(num1, num2);
}

Your program makes very little sense. Either you are using an object or you are not. You should clarify that with your instructor. This does not look like a case where you would use an object (although I'm learning that school exercises can be weird).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.