Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing values between classes in two separate files

 
Vern Vernetta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm using two separate files for the first time and seem to be having trouble passing the values. The program should add, subtract, multiply, and divide fractions printing the inputted fractions and the result.

The two files are as follows:


and file two:


When I try to run the program, it prints 0 / 0 fractions leading to a NaN result. My guess is that the values read in the first file are not being passed to the second file, but I'm unsure how to correct it.

I'd really appreciate any insight into why this is happening.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your constructor in P4Rational. You assigned the values of your membrer variables to your local variables. It's not what you wanted to do.
Change your constructor



in the following one:



You did that in the one parameter constructor too:



You must change it in:



 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic