Monday, May 24, 2010

RightTriangle function for C++?

The book I am consulting is Gary Bronson, C++ for Engineers and Scientists, Second Edition, Course Technology, 2006, ISBN 0-534-99380-X





I’m using Microsoft Visual Studios 2005 .


So here is what I’m attempting to do:


1. Write a function rightTriangle that accepts two double arguments (the two sides of a right triangle a, and b) and returns one double value (the length of the hypotenuse). The function prototype should be defined in file student.h and the function itself should be written in file student.cpp.


2. Write a program in Main.cpp that reads the two sides from a file, uses the function rightTriangle to calculate the hypotenuse length, and writes all three values to an output file.


3. Execute the program using the following triangle side input.


First Side (a) Second Side (b)


3 4


5 12


12 16


2.8 4.5








The problem is that I cannot get the function to strip values from my inFile. It says that inFile is an undeclared indentifier in my function

RightTriangle function for C++?
are you declaring that you are using a file? usually you have to use the file package


#include %26lt;fstream%26gt; in the beginning. then you need to declare your files...





ifstream inputfile.open("input.txt");


ofstream outputfile. open("output.txt");





that should fix your input problem


No comments:

Post a Comment