...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;
               }

Recommended Answers

All 5 Replies

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...

Thanks! That was not the only problem but it helped. :)

great...then mark this thread "solved"...:)

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]
BEGIN
SET i=1
SET j=2
REPEAT
IF (i/j) remainder after division is equal 0 THEN
DISPLAY (‘EVEN NUMBER’, i)
ELSE
DISPLAY (‘ODD NUMBER’,j)
ENF IF
i=i+1
UNTIL (i<10)
END

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

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

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.