/*****************************************************************/ /* Author: Chang */ /* Aim for: CS135 class */ /* Problem: Write a program that will read in two numbers from */ /* a file named numbers.data and display their sum on the screen.*/ /*****************************************************************/ //preprocessor directives #include #include // include file I/O header using namespace std; int main() { double num1, num2, sum; ifstream fin; //declare input stream object fin.open ("numbers.txt"); //open given text file // check if file open successfully: if not, exit the program with "return 1" if (!fin.good()) { cout << "Your input file did not open successfully" << endl; return 1; } else { fin >> num1 >> num2; // read in two numbers from a file sum = (num1 + num2)/100000; cout << "\nThe sum of your numbers is " << sum << endl; fin.close(); // close file } system("PAUSE"); return 0; }