Ok I am having an issue with a program. I am in C++ II but my issue is I have not taken C++ I in over a year so I am at a disadvantage...we are working on a program and this is the information we were given and this is what I have so far...

Class Compute
Add(int, int)
Subtract(int, int)
Multiply(int, int)

Data
int num1
int num 2

Need Overload constants

I really am not asking for answers but I am trying to finish the first function which is the add and after that I should be able to figure out the rest but could someone help me through the add function...hopefully this information makes sense

#include <iostream>

#include <string>

using namespace std;

class compute

{

public:

compute();

compute Add(int num1, int num2);

compute(int _num1, int _num2);

compute(int total);

compute(int _num1, int _num2, int total);

private:

int num1, num2;

int endingTotal;

};

//Constructor

compute::compute()

{

num1 = 0;

num2 = 0;

endingTotal = 0;

}

compute::compute(int _num1, int _num2)

{

num1 = _num1;

num2 = _num2;

}

compute::compute(int total)

{

endingTotal = total;

}

compute::compute(int _num1, int _num2, int total)

{

compute Add(_num1, _num2, total);

}

void compute::Add(int num1, int num2, int total)

{

num1 = _num1;

num2 = _num2;

total = endingTotal;

}

void compute::Add()

{

compute total;

cout << "Enter number 1 " << endl;

cin >> num1;

cout << "Enter number 2 " << endl;

cin >> num2;

cout << "The amount is ";

cin >> total;

cout << endl;

return 0;

}

I apologize if I did not do these code tags correctly

//..
compute::compute(int num1, int num2, int &total)
{
   //..
   add(num1,num2,total);
}
compute::add(int num1, int num2, int &total)
{
   endingtotal=num1+num2;
   total=endingtotal;
}

i dono..hope this help..

compute::compute(int _num1, int _num2)

One pice of advice , don't use '_' for the paramater names.
That's not a good style. becos the compiler itself sometimes using
these _ charater beginning variables , therefore this can be jam with them. read a style guide in C++.

void compute::Add()

{

compute total;

cout << "Enter number 1 " << endl;

cin >> num1;

cout << "Enter number 2 " << endl;

cin >> num2;

cout << "The amount is ";

cin >> total;

cout << endl;

return 0;

}

You have a void function returning 0 here.

void compute::Add(int num1, int num2, int total)

{

num1 = _num1;

num2 = _num2;

total = endingTotal;

}

This function doesn't match a prototype. Closest prototype is:

compute Add(int num1, int num2);

Also, nothing is being added in this function, is there?

I really do not use _ to start but it was in a previous example so I just went with that. So as soon as I add the prototypes and few other things...does it look like I am almost done with the add portion...only reason I ask is I am at work for the next 8 hours and do not have visio studio on my machine.

I really do not use _ to start but it was in a previous example so I just went with that. So as soon as I add the prototypes and few other things...does it look like I am almost done with the add portion...only reason I ask is I am at work for the next 8 hours and do not have visio studio on my machine.

I see no adding being done anywhere, so I don't see how you can be almost done with that portion.

I know the int is not right but I have two questions....first with the format being...

Class Compute
Add(int, int)
Subtract(int, int)
Multiple(int, int)


I was wanting to know if this format will still work...if not can someone help me out how to fix this...if it is right is everything else looking correct?

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
	void ConfigureTotal();
	string operation{string arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	int num1;
	int num2;
	string arithmetic;
	int finalTotal;
};

void Compute::ConfigureTotal()
{
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter arithmetic operation of Add, Subtract, or Multiply " << endl;
	cin >> arithmetic;
	cout << "The total is ";
	cin >> finalTotal;
}

string Compute::operation(string arithmetic, int num1, int num2)
{
	if ( arithmetic == "Add ")              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == "Subtract ")
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == "Multiply ")
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalCost << endl;
}

int main()
{

	return 0;
}
string Compute::operation(string arithmetic, int num1, int num2)
{
	if ( arithmetic == "Add ")              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == "Subtract ")
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == "Multiply ")
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

If you are returning a string, you cannot return 0. If you are returning anything, you must make sure that every possible scenario in the function returns something, not just the else clause. And unless you have a good reason to return a string, any mathematical function that adds, subtracts, or multiplies should return a number, not a string, so i think you should change the function so it does not return a string..

is this kind of what you are talking about....

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
	void ConfigureTotal();
	string operation{int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	int num1;
	int num2;
	int arithmetic;
	int finalTotal;
};

void Compute::ConfigureTotal()
{
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	cout << "The total is ";
	cin >> finalTotal;
}

string Compute::operation(int arithmetic, int num1, int num2)
{
	if ( arithmetic == 1)              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalCost << endl;
}

int main()
{

	return 0;
}

I am getting these errors all with the same function...i think I have it right but obviously something is wrong...Ill give the errors I am getting as well...

Error 1 error C2473: 'operation' : looks like a function definition, but there is no parameter list. c:\documents and settings\bryan kruep\desktop\program 1\program 1.cpp 10

Error 2 error C2062: type 'int' unexpected c:\documents and settings\bryan kruep\desktop\program 1\program 1.cpp 10

Error 3 error C2063: 'Compute::operation' : not a function c:\documents and settings\bryan kruep\desktop\program 1\program 1.cpp 32

Can anyone tell what is wrong with my function....

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
	void ConfigureTotal();
	int operation{int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	int num1;
	int num2;
	int finalTotal;
};

void Compute::ConfigureTotal()
{
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	cout << "The total is ";
	cin >> finalTotal;
}

int Compute::operation(int arithmetic, int num1, int num2)
{
	if ( arithmetic == 1)              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalTotal << endl;
}

int main()
{

	return 0;
}

I think I made some positive changes. For one I changed the string of the arithmetic to a number instead. I think this will be easier to follow. I also had a question with getting the rest of this set up. I am still getting 4 errors. Does anyone see any additional issues I am having....

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
	void ConfigureTotal();
	int operation{int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	
	int finalTotal;
};

void Compute::ConfigureTotal()
{
	int num1 = 0, num2 = 0;
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	operation(arithmetic, num1, num2);
	cout << "The total is ";
	cin >> finalTotal;
}

int Compute::operation(int arithmetic, int num1, int num2)
{
	if ( arithmetic == 1)              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalTotal << endl;
}

int main()
{

	return 0;
}

You must pay very close attention to the error messages and approach the debugging process in a very systematic fashion. Realize that errors compound on each other, so pay attention to the first one, ignore the others, comment out lines of code, fix them, uncomment them, try again, recompile, comment out more, recompile, uncomment, etc. Realize that a missing semicolon, a missing bracket, or an extra bracket, screws up everything, even the code that is correct. So you always start by commenting out everything in the class and having the simplest main function possible and see if it compiles, It will. Now uncomment the class declarations, but keep the implementation commented and compile again:

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
	void ConfigureTotal();
	int operation{int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	
	int finalTotal;
};
/*
void Compute::ConfigureTotal()
{
	int num1 = 0, num2 = 0;
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	operation(arithmetic, num1, num2);
	cout << "The total is ";
	cin >> finalTotal;
}

int Compute::operation(int arithmetic, int num1, int num2)
{
	if ( arithmetic == 1)              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalTotal << endl;
}
*/
int main()
{

	return 0;
}

It won't compile, so there is a problem with your class declarations. Start commenting and uncommenting stuff out from the bottom up (or the top down) till it compiles without error. That'll tell you, if the error messages don't, where your problem line is.

This compiles:

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
//	void ConfigureTotal();
//	int operation{int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	
	int finalTotal;
};
/*
void Compute::ConfigureTotal()
{
	int num1 = 0, num2 = 0;
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	operation(arithmetic, num1, num2);
	cout << "The total is ";
	cin >> finalTotal;
}

int Compute::operation(int arithmetic, int num1, int num2)
{
	if ( arithmetic == 1)              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalTotal << endl;
}
*/
int main()
{

	return 0;
}

This doesn't:

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
//	void ConfigureTotal();
	int operation{int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	
	int finalTotal;
};
/*
void Compute::ConfigureTotal()
{
	int num1 = 0, num2 = 0;
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	operation(arithmetic, num1, num2);
	cout << "The total is ";
	cin >> finalTotal;
}

int Compute::operation(int arithmetic, int num1, int num2)
{
	if ( arithmetic == 1)              )
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalTotal << endl;
}
*/
int main()
{

	return 0;
}

So you have a problem in this line:

int operation{int arithmetic, int num1, int num2);

There are other strategies, but most revolve around systematically commenting and uncommenting code and seeing what compiles, as well as paying close attention to the top error messages and mostly ignoring the other error messages. Fix the error and start the process over again.

I have gotten it to compile but closes as soon as it compiles...

#include <iostream>
#include <string>

using namespace std;

class Compute
{
public:
	void ConfigureTotal();
	int operation(int arithmetic, int num1, int num2);
	void displayFinalCost();

private:
	
	int finalTotal;
};

void Compute::ConfigureTotal()
{
	int num1 = 0, num2 = 0;
	int arithmetic;
	cout << "Enter first number " << endl;
	cin >> num1;
	cout << "Enter second number " << endl;
	cin >> num2;
	cout << "Enter 1 for Add arithmetic "<< endl << "Enter 2 for Subtract arithmetic " << endl << "Enter 3 for Multiply arithmetic " << endl;
	cin >> arithmetic;
	operation(arithmetic, num1, num2);
	cout << "The total is ";
	cin >> finalTotal;
}

int Compute::operation(int arithmetic, int num1, int num2)
{
	if (arithmetic == 1)              
	{
		finalTotal = num1 + num2;
	}
	else if (arithmetic == 2)
	{
		finalTotal = num1 - num2;
	}
	else if (arithmetic == 3)
	{
		finalTotal = num1 * num2;
	}
	else
		return 0;
}

void Compute::displayFinalCost()
{
	cout << finalTotal << endl;
}

int main()
{

	return 0;
}

Here is your program.

#include <iostream>
#include <string>

using namespace std;


int main()
{

	return 0;
}

You can take the class out of the code because the class is never used. Your program is a single line:

return 0;
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.