-4
#include <iostream>
#include <math.h>

using namespace std;

int Square(int num, int& Answer);
int Triangle(int num);

int main(int argc, char **argv)
{
    int num = -1;
    int Answer;
  //Prompts the user for the length of the sides and doesnt stop until they     enter a valid input
while(num >= 6 || num <= 1){
    cout<<"Enter a number from 1 to 6: ";

    cin>>num;
    }

Square(int num, int& Answer);
Triangle(int num, int&Answer);


}

int Square(int num, int& Answer){
    Answer = num * num;
    cout<<Answer;
}

int Triangle(int num, int& Answer){
    Answer = .5 * (num * num);
    cout<<Answer;
}

I'm not sure what I ma doing wrong but the error I keep getting is, expected primary-expression before 'int'

This is where the error is and it shows up on each instance of int

Square(int num, int& Answer);
Triangle(int num, int&Answer);
  • 2
    `Square(int num, int& Answer);` does not call a function, `#include ` has been deprecated for almost two decades now and `using namespace std;` is bad. You need better learning material or should read the material you have more carefully. – Baum mit Augen Jan 13 '17 at 22:42
  • 1
    See http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list for more information. – Sam Varshavchik Jan 13 '17 at 22:42

1 Answers1

2

this is not how to call a function:

Square(int num, int& Answer);
Triangle(int num, int&Answer);

correct it to:

Square  (num, Answer);
Triangle(num, Answer);
  • also include cmath instead of math.h:

    #include <cmath>
    
  • also the function triangle takes only one parameter and you are passing ot it two parameters:

    Triangle(int num, int&Answer);
    

so either pass num or answer.

  • another thing: why passing Answer as a parameter?

you can pass only num and the return value of each function store it in Answer. an example is like this:

#include <iostream>
//#include <cmath> // if you don't need it don't include it
using namespace std;

int Square  (int num); // Square needs only parameter and returns the result in return value
int Triangle(int num); // the same as above

int main(int argc, char **argv)
{
    int num = -1;
    int Answer;
  //Prompts the user for the length of the sides and doesnt stop until they     enter a valid input
    while(num >= 6 || num <= 1){
        cout<<"Enter a number from 1 to 6: ";
        cin >> num;
    }

    Answer = Square(num); // here I assign the return value of Square to Answer
    cout << "Squre( " << num << " ) = " << Answer << endl;  // check
    Answer = Triangle(num); // the same as above
    cout << "Triangle( " << num << " ) = " << Answer << endl;

    return 0;
}

int Square(int num){
    return (num * num); // store the result in return address
}

int Triangle(int num){
     return ( .5 * (num * num));
}
Raindrop7
  • 3,889
  • 3
  • 16
  • 27