Advertisement
ASP_Volume2 Miscellaneous #40969

Code Example - C++ Homework Assignment (3 sides of a triangle)

was a C++ homework assignment my class had to do. Simply inputs 3 integers, and says whether or not they would be a right triangle.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#include<iostream>
using namespace std;
int getinteger();
int main()
{
	system("cls");
	cout << " three sides of a triangle \n ";
	cout << "\n enter side one: ";
	int x,y,z;
	x = getinteger();
	cout << "\n enter side two: ";
	y = getinteger();
	cout << "\n enter side three: ";
	z = getinteger();
	
	if(x*x + y*y == z*z)
	{
		cout << "\n you have a right triangle ! ";
	}
	else
	{
		cout << "\n have do not have a right triangle ! ";
	}
	char ans;
	cout << "\n do you wish to run this program again?(y/n): ";
	cin >> ans;
	if(ans == 'y' || ans == 'Y')
	{
		return main();
	}
	return (0);
}

int getinteger()
{
	char dat[25];
	cin >> dat;
	int val = atoi(dat);
	if(val < 0)
	{
		cout << "\n value must be a positive integer\n ";
		return getinteger();
	}
	if(val == 0)
	{
		cout << "\n value must be greater then zero, and a integer " << endl;
		return getinteger();
	}
	return val;
}
Original Comments (3)
Recovered from Wayback Machine