The c++ question:
Assume that there is a valid file cards.txt in the current directory which contains 5 valid int values, each on its own line. Write a function which reads all the values from the file and prints out the message “Lucky 7!” to the screen for every 7 it sees. Your function must have the following signature:
void printSevens();
#include <iostream> #include <fstream> using namespace std; void printSevens(); int main() { printSevens(); return 0; } void printSevens() { ifstream in("cards.txt"); if (in.is_open()) { int n; while (in >> n) { if (n == 7) cout << "Lucky 7!" << endl; } in.close(); } else { cout << "cards.txt does not exists!" << endl; } }
Get Answers For Free
Most questions answered within 1 hours.