| joe26 (2) | |
|
we had our project in C + +. The loop should continue when open again.... help .. help ... help... | |
|
|
|
| ResidentBiscuit (2215) | |
| I don't even know what you just said. | |
|
|
|
| joe26 (2) | |
|
sorry for my bad english. what i mean is... my teacher gave us a project in c++ that will loop a counting number in text file... when I enter a sting, it will print into the text file I've made, then asking for continue. but when I close the console and open it again, it returns to 1. Now what I want is , it will continue to number 2 when I open it and enter a string. please help me,.. here's my code #include <cstdlib> #include <iostream> #include <windows.h> #include <fstream> using namespace std; void gotoxy (int x, int y); void color (int e); int main() { int sum = 0; ha: ofstream myfile ("record.txt",ios::app); string pro, pre; for (int i = 0; i < 2; i++) {sum = sum + i;} //first command gotoxy(5,6); cout<<" record #"<<sum<<endl; gotoxy(5,7); color(30); cout<<" Name : "; color(255); cout<<" "; //cursor color(30); gotoxy(21,7); getline(cin,pro); color(0); system("cls"); gotoxy(30,8); color(30); cout<<" Name : "; color(185); gotoxy(38,8); cout<<pro<<endl<<endl<<endl<<endl; color(255); gotoxy(5,14); cout<<" "; myfile<<"record # "<<sum<<endl<<pro<<endl; myfile.close(); here: color(881); gotoxy(5,14); cout<<"continue ? :"; color(30); gotoxy(20,14); getline(cin,pre); color(185); gotoxy(38,8); cout<<pre<<endl<<endl<<endl<<endl; if (pre == "Y"||pre == "y") { color(7); system("cls"); goto ha; } else if (pre == "N"||pre == "n") { return 0; } else { goto here; } } void color(int e){ WORD color={e}; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color); } void gotoxy (int x,int y){ COORD coord = {x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); } sorry for the color | |
|
Last edited on
|
|
| Pickle Gunner (63) | |||
Use the code tags:
It makes your code more legible. | |||
|
Last edited on
|
|||