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 Subtract(int num1, int num2);
int Multiply(int num1, int num2);

private:

};

{
cout << "The two numbers added together are: ";
}

//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;
Subtract(num1, num2);
Multiply(num1, num2);
}``````
4
Contributors
7
Replies
9
Views
9 Years
Discussion Span
Last Post by nucleon

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 Subtract(int num1, int num2);
int Multiply(int num1, int num2);

private:

};

{
cout << "The two numbers added together are: ";
}

//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;
Subtract(num1, num2);
Multiply(num1, num2);
}``````

``````//Adding the two numbers together
{
// sum up the values ...
// display text ...
cout << "The two numbers added together are: ";
// get the value from user ... why?
// return the value gotten from user ...
}``````

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

"ComeauTest.c", line 56: error: identifier "Add" is undefined
^

"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 Subtract(int num1, int num2);
int Multiply(int num1, int num2);

private:

};

{
cout << "The two numbers added together are: ";
}

//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;
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 Subtract(int num1, int num2);
int Multiply(int num1, int num2);

private:

};

{
cout << "The two numbers added together are: ";
}

//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;
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;
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).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.