Formatting with loops and i/o filestream objects

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" ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  
#include<iomanip>
#include<iostream>
#include<string>
#include<cmath>
#include<fstream>
#include<cstdlib>
 
using namespace 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;
}
Last edited on
Topic archived. No new replies allowed.