Hi, my problems are that i am getting repeated output statements sometimes when i try to repeat or "update" the info., or I am repeating a loop that I don't want to. I have been playing around with it for a while but can't seem to get the right order of things. How can I break out of my 'if' statement and go to the else when the user enters anything other than "yes" ?
#include<iomanip>
#include<iostream>
#include<string>
#include<cmath>
#include<fstream>
#include<cstdlib>
usingnamespace std;
int main()
{
string info;
ofstream file1;
ifstream file2;
string ans;
string repeat = "yes";
while(repeat == "yes")
{
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;
if(ans == "yes")
{
file2.open("original.txt.");
cout<<endl<<"Your current info is "<<info<<endl<<endl;
file1.open("changed_info.txt");
cout<<"Please input your name and updated address"<<endl;
getline(cin,info);
}
else
{
cout<<"Thank you for using this program"<<endl;
cout<<"Do you want to run this again?"<<endl;
cin>>repeat;
}
}
system("pause");
return 0;
}