I wrote this program, however, it is not giving me the correct output and I do n
ID: 3656055 • Letter: I
Question
I wrote this program, however, it is not giving me the correct output and I do not know what I need to do to correct this. I want the output to show the do while statements repeating if name does not equal Topicin2.txt or Topicin.txt. But if name equals either of those, I want it to display one of the if's, then terminate. However, it asks for a file name twice, but if I delete it from the do while, the do while becomes a continous loop. #include #include #include using namespace std; int main() { string name; cout << endl << "Enter a file name --> "; cin >> name; if(name == "Topicin.txt") { cout << "Storage full - Not all file values read" << endl; cout << "Contents of the array are:" << endl; } else if(name == "Topicin2.txt") { cout << "Problem with input file" << endl; cout << "Program ending" << endl; cout << "Press Enter to end -->" << endl; } do { cout << endl << "Enter a file name --> "; cin >> name; cout << "Cannot open " << name << endl; cout << "Enter another name" << endl; }while(!(name == "Topicin.txt" || name == "Topicin2.txt")); return 0; }Explanation / Answer
#include #include #include using namespace std; int main() { string name; cout name; if(name == "Topicin.txt") { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.