Sep 26, 2012 at 5:14pm UTC
we had our project in C + +. The loop should continue when open again....
help .. help ... help...
Sep 26, 2012 at 6:47pm UTC
I don't even know what you just said.
Sep 27, 2012 at 9:14am UTC
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 Sep 27, 2012 at 12:18pm UTC
Oct 13, 2012 at 7:45pm UTC
Use the code tags:
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#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);
}
It makes your code more legible.
Last edited on Oct 13, 2012 at 7:46pm UTC