...so I'm trying to make a program that takes in the three sides of a triangle and then decides whether the triangle is equilateral, isosceles or equilateral.
I have to have 2 different functions and I can't use global variables ( That's what my teacher wants ). My main function keeps looping which is not what i want my program to do. I couldn't find what im doing wrong. Any help is appreciated.

P.S. I don't use dev C++ anymore. I've started using Code::Blocks.

Here's my code-

#include <cstdlib>
#include <iostream>

using namespace std;

int calculations();
int main(){

    int side1 = 0;
    int side2 = 0;
    int side3 = 0;

    cout << "Enter side 1: " << endl;
    cin >> side1;

    cout << "Enter side 2: " << endl;
    cin >> side2;

    cout << "Enter side 3: " << endl;
    cin >> side3;

    calculations(side1, side2, side3);
    return 0;

int calculations(){

cout << side1 << endl;

    int side1 = main();
    int side2 = main();
    int side3 = main();

    if ((side1 == side2)&&(side1 == side3)&&(side2 == side3)){
               cout << "The triangle is Equilateral" << endl;

    if ((side1 == side2)||(side1 == side3)||(side2 == side3)){
               cout << "The triangle is Isosceles" << endl;

    if ((side1 != side2)&&(side1 != side3)&&(side2 != side3)){
               cout << "The triangle is Scalene" << endl;

    cout << "" << endl;

 return 0;

Edited by networkZombie: Forgot to put my code

6 Years
Discussion Span
Last Post by Dingbats

okay, firstly, repeat this a 100 times,

"I'll never call main() from other functions"

main() is supposed to be called by the OS, and it will get really angry if you call it instead..!!

so remove all those calls to main() (line no. 31 to 33) and you'll get out of that loop...

oh, btw, you'll have to pass the sides to your calculations() function like this:

void calculations (int side1, int side2, int side3)
    // Do calculations

and offcourse, change the prototype suitably...

P.S: your main logic for triangle checking is flawed...

Edited by NP-complete: n/a


Homework Help please

Design and write Pseudocode for the following problems.
1. Display the table from one to ten for a number that is entered by the user from keyboard. The program should keep on asking for number and displaying tables until user presses escape key from keyboard. [10]
2. The program should display the grade for a student whose marks are entered from keyboard. The display criteria is as follows; if marks are below 60 the student is fail (F), if marks are between 60 and 64 the student has achieved C, if between 65 and 69 then C+, if between 70 and 74 then B, if between 75 and 79 then B+ and if above eighty then the student has achieved A grade. [15]
3. Find out the procedure for calculating GPA of a semester result and write an algorithm for its calculation where a user can enter grades from keyboard and the program will calculate CGPA and display it on screen. [15]
4. Write the output from the following pseudocode; [10]
SET i=1
SET j=2
IF (i/j) remainder after division is equal 0 THEN
UNTIL (i<10)

please help me i have to submit this assignment tomorrow help me asap it woulb great help thanx


You shouldn't hijack threads. Please start your own, and that way you much more likely to get a response.

Edited by Dingbats: n/a

This question has already been answered. 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.