can someone please put me through on calling functions and avoiding using goto in d example below:
#include <iostream>
#include <string>
using namespace std;
float psquare (float a)
{
return (4*a);
}
float prectangle (float w, float l)
{
return ((2*w)+(2*l));
}
int main()
{
float d,a,w,l;
char n;
cout << "Please choose from options below:\t";
cout << "1. Square\n";
cout << "2. Rectangle\n";
cin >> d;
if ( d == 1 )
{
cout << "length of side:\t";
cin >> a;
{return psquare;}
goto end;
}
else if ( d == 2 )
{
cout << "length of side:\t";
cin >> w,l;
{return prectangle;}
goto end;
}
else
{
cout << "invalid input, Please try again\n\n";
return main ();
}
end:
cout <<"Do you want to calculate an other shape? (y / n):";
cin >>n;
if (n == 'y')
{ return main();}
system("pause");
return 0;
}
please i need help as i am really confused....please......
MOD EDIT: When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 30 October 2010 - 05:46 AM
Reason for edit:: Added code tags & formatted code via indentation

New Topic/Question
Reply



MultiQuote


|