My problems are that I am getting some of my output repeated twice and that when i hit anything other than "yes" to repeat the loop I get some of the output that is only supposed to be in the loop. Is my do while loop in the right place? or am i using my i/o streams in the wrong place?
#include<iomanip>
#include<iostream>
#include<string>
#include<cmath>
#include<fstream>
#include<cstdlib>
usingnamespace std;
int main()
{
string info;
ofstream file1;
ifstream file2;
string ans;
file1.open("original.txt.");
cout<<"Please enter your name and street address"<<endl<<endl;
getline(cin, info);
file1<<info;
system("cls");
cout<<"Would you like to update your street address?"<<endl;
cin>>ans;
do{
file2.open("original.txt.");
cout<<info<<endl<<endl;
file1.open("changed_info.txt");
cout<<"Please input your name and updated address"<<endl;
getline(cin,info);
}
while (ans == "yes");
cout<<"Thank you for using this program"<<endl;
system("pause");
return 0;
}
Also what if I enter no for ans you still enter the loop because it is a do while switch to a while. Once you are in your loop how does ans get updated to exit the loop?
what is "cin.sync()" ? we haven't learned that yet. and ok, that makes sense. Could I put an exit(1) (i think thats the code) somewhere to exit the program?