wrong check for Batch code entry end condition?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int check_Pythag(int DIMA, int DIMB, int DIMC)
{
if (DIMA*DIMA == DIMB*DIMB + DIMC*DIMC) // This where the the Pythagoaras equation is that calculates whether or not it is a right angled triangle.
{
return 'Yes'; // In this section if it is a right angle the program will then return the answer "Batch no. " " Yes". If it isn't then it will reportback that the batch code was not right angled. But if DIMA is the biggest/longest then the message "Invalid Data" will appear.
}
else
{
return 'No';
}
}

int main()
{
int DIMA; int DIMB; int DIMC;
string batch;

cout << "Pythagoras Theorum" << endl << endl; // Title at the top of the program.

cout << "Enter Batch No. :- "; // This is were we enter the Batch code no.
cin >> batch;
while (batch != "0")

{

cout << "Enter Dimension A :-"; // At this stage we obtain Dimension A, B & C from the user.
cin >> DIMA;

cout << "Enter Dimension B :-";
cin >> DIMB;

cout << "Enter Dimension C :-";
cin >> DIMC;

if (DIMA <= DIMB || DIMA <= DIMC) // This calculates if Dimension A is indeed the longest (or biggest).
{
cout << "Invalid Data"; // If DimensionA is not longest report error to user - "Invalid Data".
std::cin.ignore(INT_MAX);
cin.get(); // This code is here as once you input Dimension C the program would close.
}
else

if (check_Pythag(DIMA, DIMB, DIMC) == 'Yes')
{
cout << endl << "Batch No. " << batch << " Yes"; // This message will be displayed if the Batch code No. entered equals a right angle.
cout << endl << endl;
}
else
{
cout << endl << "Batch No. " << batch << " No"; // This message will be displayed if the Batch code No. entered doe's not equal a right angle.
cout << endl << endl;
}
cout << "Enter Another Batch No. (0 to Exit) :- "; // This message prompts the user for another Batch of numbers.
cin >> batch;
}
}
You've told the compiler that check_Pythag returns an int, so why are you trying to return a string?
If i was you i'd make it return a bool, and return true or false depending on your logic.


edit:i have no idea what a batch code is and am not sure how it fits in with the rest of your code.
Last edited on
I'm having trouble implementing the bool. Program won't run with it so how would I implement it exactly?
Program won't run with it

This is pretty useless information to be honest.
Can you post updated code please? (and post them in code tags as well please?).
This is a duplicate topic.

dhayden gave the answer in the other one.

This is why duplicate topics are annoying.
Topic archived. No new replies allowed.