#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <iomanip>
#include <ctype.h>
#include <windows.h>
#include <cstring>
#include <ctime>
using namespace std;
int main()
{
    ofstream outputparticulars("particulars.txt",ios::out);
     int d,a,b,c;
     char ic[100],password[100],confirmpassword[100];
     char info[6][101];
     cin>>d;
     if(d==1)

     {cout<<"1"<<endl;
     }
     else if(d==3)
     {    
     cout<<" Key in your......\n";
     cout<<" First Name : ";
     cin.getline(info[0],100);
   
     outputparticulars<<" Name : "<<info[0]<<endl;
     cout<<" IC Number (with the hyphens, eg: 910101-07-1111) : ";
     cin.getline(info[1],100);
     outputparticulars<<" IC Number (with the hyphens, eg: 910101-07-1111) : "<<info[1]<<endl;
     cout<<" Matric Number : ";
     cin.getline(info[2],100);
     outputparticulars<<" Matric no : "<<info[2]<<endl;
     cout<<" Course : ";
     cin.getline(info[3],100);
     outputparticulars<<" Course : "<<info[3]<<endl;
     cout<<" Please enter your desired password (Case Sensitive) : "<<endl;
     cin.getline(password,100);
     cout<<" Please re-confirm your password (Case Sensitive) : "<<endl;
     cin.getline(confirmpassword,100);
     }    
}

i got a strange output. why is this so?? if i cancel the IF condition. the program runs the way that i want. can anyone help me with this??? I've been thinking and doing this problem for 5hours and i cant find out what's wrong.

Recommended Answers

All 6 Replies

A word of advice, don't mark your thread with "URGENT" that actually makes it more likely to be ignored. It may be "URGENT!!!" for you, but it isn't for us.

I'm not sure what you did, but I can't read your comment(s) well enough to help much. Did you try to put it in a TEX block or something? Here's a hint, don't.

Also, please be sure you explain your problem fully and clearly. Otherwise we have no idea what you define as "strange output" (at least that's what I think you called it).

I've obtained a strange output. Why is this so? If i cancel the IF condition, the program runs the way that i want it to be. Can anyone help me with this?? I've been thinking and doing this problem for 5hours already. T__T

Please explain your problem fully and clearly. Otherwise we have no idea what you define as "strange output".

What are you getting, and how does it vary from what you expect?

A word of advice, don't mark your thread with "URGENT" that actually makes it more likely to be ignored. It may be "URGENT!!!" for you, but it isn't for us.

I'm not sure what you did, but I can't read your comment(s) well enough to help much. Did you try to put it in a TEX block or something? Here's a hint, don't.

Also, please be sure you explain your problem fully and clearly. Otherwise we have no idea what you define as "strange output" (at least that's what I think you called it).

I obtained an output like this.


key in your..........
First Name : IC Number(with hyphens...):

But i wanted an output like this instead... The condition IF somehow ignored the info[0] and skipped to the next part. if i take away the IF condition, the program runs smoothly


Key in your.....
First name :

The variable 'd' is an integer. When reading numeric data, the "extraction operator" ('>>') does not extract the newline that is placed in the input stream when you press the ENTER key. As a result, the '\n' character lingers in the stream. Then your code hits Line 26 ( cin.getline(info[0],100); ), the line reads that lingering newline as its input and moves on instead of waiting for your input.

Read this sticky.

the variable 'd' is an integer. When reading numeric data, the "extraction operator" ('>>') does not extract the newline that is placed in the input stream when you press the enter key. As a result, the '\n' character lingers in the stream. Then your code hits line 26 ( cin.getline(info[0],100); ), the line reads that lingering newline as its input and moves on instead of waiting for your input.

read this sticky.

thank you very much! You saved my day! =d thankssssssssssssss

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.