Looping error

Hey there. Here's the problem. My do-while statements are correct, the program is running but it does not loop/goes back to the first step when the condition's satisfied, neither does it exterminate when the condition is false. Here's the code (ignore the codes for frames and forms):

#include <iostream.h> //header files
#include <conio.h>
#include <cstring>
#include <stdlib>
#include <fstream> //header for fstreaming of files

void form(int, int, int, int, int, int); //for form
void frame(int, int, int, int, int, int);//for frame

void sample(void);

void main(void)
{
char ans[1];

clrscr();
do{
form(3,3,80,38, YELLOW,WHITE);
gotoxy(40,18);cprintf("");
frame(2,2,79,37, LIGHTMAGENTA,WHITE); //size and color of the frame
frame(1,1,80,38,WHITE,LIGHTMAGENTA);
gotoxy(4,4); cprintf("Girl Scouts of the Philippines Registration Form");
ofstream input;
string content2;
input.open("sample.xls");
if (input.good())
{
char last[60]; char first[60]; char middle[60];
char age[3];
char yrsec[15];
char bday[9];
cout<<"Last Name: "; cin.getline(last,60);
input<<last;
cout<<"First Name: "; cin.getline(first, 60);
input<<first;
cout<<"Middle Initial: "; cin>>middle;
input<<middle;
cout<<"Age: "; cin>>age;
input<<age;
cout<<"Year-Section: "; cin>>yrsec;
input<<yrsec;
cout<<"Birthday [mm/dd/yy]: "; cin>>bday;
input<<bday;
}

gotoxy(4,18);cprintf("Do you wish to input more files? [y/n] ");
cin>>ans;

}while(ans=="y"||ans=="Y");

}

void form(int x1, int y1, int y2, int x2, int forecolor, int backcolor)

{
textcolor(forecolor); textbackground(backcolor);
for(int k = y1; k <= y2; k++)
for(int h = x1 ; h <= x2; h++)
{gotoxy(h,k); cprintf("");}

}

void frame(int x1, int y1, int x2, int y2, int color, int bgcolor)
{
textcolor(color);
textbackground(bgcolor);
for(int x = x1+1; x < x2; x++)
{
gotoxy(x,y1); cprintf("Ä");
gotoxy(x,y2); cprintf("Ä");

}
for (int y= y1+1; y < y2; y++)
{
gotoxy(x1,y); cprintf("³");
gotoxy(x2,y); cprintf("³");
}
gotoxy(x1,y1); cprintf("Ú");
gotoxy(x2,y1); cprintf("¿");
gotoxy(x1,y2); cprintf("À");
gotoxy(x2,y2); cprintf("À");
}

Change the type of ans to std::string.
 
while(ans=="y"||ans=="Y");


You're comparing ans to a string literal, not a character literal.
ans is declared as a char.

It should be:
 
while(ans=='y'||ans=='Y');




PLEASE USE CODE TAGS (the <> formatting button) when posting code.
char ans[1];
should be a single character like this:
char ans;

The first version specifies a null-terminated string which has space for nothing apart from the null terminator. Its use like this cin>>ans; will cause corruption of some other data, with unpredictable results, most likely a program crash.

sorry about not using the code tags format >.< my first time. But anyway, it works now. Thanks for your help ^___^
Topic archived. No new replies allowed.