modifying main() to enable interactive data entry

Mar 11, 2009 at 7:44pm
Hi

I am a little stuck with a fraction program where currently it uses simple but inflexible literal values to show the adding of a fraction, It has three files called fract.h, TestClassFract.cc and fract.cc. I need help in being able to let the user input values themselves instead of using these inflexible literal values,I have attepmted to do this myself (as is shown in the second code block), but get the errors shown in the third code block. Can you tell me what I am doing wrong and how I would be able to make the change to main() in order for users to be able to input their own values for the numerator and denominator? The original main() code is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include "fract.h"

using namespace std;

int main()
{
   Fraction f1, f2, f3;

   f1.create(1,2);
   f2.create(1,4);
   f1.add(f2,f3);
   f1.display();	
   cout << " + ";
   f2.display();
   cout << " = ";
   f3.display();	
   cout << endl;
   
   return ( 0 );
}


my attempt at it was:
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
#include <iostream>
#include "fract.h"

using namespace std;

int main()
{
   Fraction f1, f2, f3;
   int numerator; 
   int denominator; 
   int numerator2;
   int denominator2;
   
   cout << "Enter first numerator: ";
   cin >> numerator << endl;
   cout << "Enter first denominator: ";
   cin >> denominator << endl;
   cout << "Enter second numerator: ";
   cin >> numerator2 << endl;
   cout << "Enter second denominator: ";
   cin >> denominator2 << endl;

   f1.create(numerator,denominator);
   f2.create(numerator2,denominator2);
   f1.add(f2,f3);
   f1.display();	
   cout << " + ";
   f2.display();
   cout << " = ";
   f3.display();	
   cout << endl;
   
   return ( 0 );
}

The errors I got were:
1
2
3
4
5
TestClassFract.cc: In function `int main()':
TestClassFract.cc:12: no match for `istream & << ostream & (&)(ostream &)'
TestClassFract.cc:14: no match for `istream & << ostream & (&)(ostream &)'
TestClassFract.cc:16: no match for `istream & << ostream & (&)(ostream &)'
TestClassFract.cc:18: no match for `istream & << ostream & (&)(ostream &)' 


Any help would be great.Thanks in advance.
Mar 11, 2009 at 8:13pm
Remove the << endl from all your cin lines. That should clear things up a bit.
Mar 11, 2009 at 8:23pm
Thanks, your reply came too late however, I figured it out in the end.
Topic archived. No new replies allowed.