Okay, so I tried it by reference first
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <cstdlib>
#include <iostream>
using namespace std;
struct fraction//struct creation
{
int num;
int denom;
bool positive;
}fraction;
void fracMult(fraction& f1,fraction& f2, fraction& fresult);// Function declaration
/*2
*
*/
int main(int argc, char** argv)
{
fraction f1,f2,fresult;//made two new fraction structs.
char tempchar;
cout << "Input the first numerator"<<endl;
cin >> f1.num;
cout << "input the first denominator"<< endl;
cin >> f1.denom;
cout << "Is the fraction positive?(Y or N)"<<endl;
cin >> tempchar;
if (tempchar=='Y')//If the the value is positive, tempchar=true, else, it is false.
f1.positive=true;
else f1.positive=false;
cout << "Input the second numerator"<<endl;
cin >> f2.num;
cout << "input the second denominator"<< endl;
cin >> f2.denom;
cout << "Is the fraction positive?(Y or N)"<<endl;
cin >> tempchar;
if (tempchar=='Y')
f2.positive=true;
else f2.positive=false;
fracMult(f1,f2,fresult);
cout<< "the result is: ";
if(!fresult.positive)//if the statement is false, add a - sign.
{
cout << "-";
}
cout << fresult.num << "/" << fresult.denom << endl;
return 0;
}
fraction fracMult(fraction& f1, fraction& f2, fraction& fresult)//
{
fresult.num=f1.num*f2.num;
fresult.denom=f1.denom*f2.denom;
if(f1.positive==f2.positive)
{
fresult.positive=true;
}
else fresult.positive=false;
return fresult;
}
|
When I try and build, I get tons of errors but nothing is highlighted in netbeans.
ERRORS
fraction.cpp:24:15: error: variable or field ‘fracMult’ declared void
void fracMult(fraction& f1,fraction& f2, fraction& fresult);// Function declaration
^
fraction.cpp:24:25: error: ‘f1’ was not declared in this scope
void fracMult(fraction& f1,fraction& f2, fraction& fresult);// Function declaration
^
fraction.cpp:24:38: error: ‘f2’ was not declared in this scope
void fracMult(fraction& f1,fraction& f2, fraction& fresult);// Function declaration
^
fraction.cpp:24:52: error: ‘fresult’ was not declared in this scope
void fracMult(fraction& f1,fraction& f2, fraction& fresult);// Function declaration
^
fraction.cpp: In function ‘int main(int, char**)’:
fraction.cpp:30:14: error: expected ‘;’ before ‘f1’
fraction f1,f2,fresult;//made two new fraction structs.
^
fraction.cpp:33:12: error: ‘f1’ was not declared in this scope
cin >> f1.num;
^
fraction.cpp:42:12: error: ‘f2’ was not declared in this scope
cin >> f2.num;
^
fraction.cpp:51:20: error: ‘fresult’ was not declared in this scope
fracMult(f1,f2,fresult);
^
fraction.cpp:51:27: error: ‘fracMult’ was not declared in this scope
fracMult(f1,f2,fresult);
^
fraction.cpp: At global scope:
fraction.cpp:61:1: error: ‘fraction’ does not name a type
fraction fracMult(fraction& f1, fraction& f2, fraction& fresult)//
^
make: *** [fraction] Error 1
CLEAN FAILED (exit value 2, total time: 465ms)