whats wrong with this coding ??? help me!!

got a few failed.. but i dont know how to know what it is..
help me please

#include <iostream>
using namespace std;
void main()

{
char User_Name [30];
char Ic_Number [30];
char House_Name [30];
double Come_Back_Time;
int a;
int password (a = 1234);
int *ptrPointer;
ptrPointer = &a;

do
{ cout<<"Please enter your password :";
cin>>a;
cout<<"True"<<endl;

cout<<"Enter the User_Name :";
cin>>User_Name;

cout<<"Enter your Ic_Number :";
cin>>Ic_Number;

cout<<"Enter the House_Name :";
cin>>House_Name;

cout<<"Your Come_Back_Time is :";
cin>>Come_Back_Time;

cout<<"\n\n\t\t\t\t Welcome "<<User_Name<<endl;
cout<<"\n\t\t Your Ic Number is :"<<Ic_Number<<endl;
cout<<"\n\t\t Your Come Back Time today is :"<<Come_Back_Time<<endl;

if (Come_Back_Time <= 17.00)
{
cout<<"\n\t\t You are :Early"<<endl;
}
else
{
cout<<"\n\t\t You are :Late"<<endl;
}
while(a!=1234)
cout<<"Try again"<<endl;
}
}
void main() is not C++. In C++, main returns an int.

int password (a = 1234); Are you trying to set the variable a with a value, or create a new variable, or both, or what?


If that while is meant to be the end of a do-while loop; if you indent your code properly, you will see that you have got your braces wrong. The do loop isn't closed properly, and also you're missing a semi-colon after the while.
Last edited on
It's hard to understand the meaning (or even the intended meaning) of this code without proper indentation. If you use code tags [code]like this[/code] - use the <> formatting button on the right, it will help.

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
#include <iostream>
using namespace std;
void main()
{
    char User_Name [30];
    char Ic_Number [30];
    char House_Name [30];
    double Come_Back_Time;
    int a;
    int password (a = 1234);
    int *ptrPointer;
    ptrPointer = &a;

    do { 
        cout<<"Please enter your password :";
        cin>>a;
        cout<<"True"<<endl;

        cout<<"Enter the User_Name :";
        cin>>User_Name;

        cout<<"Enter your Ic_Number :";
        cin>>Ic_Number;

        cout<<"Enter the House_Name :";
        cin>>House_Name;

        cout<<"Your Come_Back_Time is :";
        cin>>Come_Back_Time;

        cout<<"\n\n\t\t\t\t Welcome "<<User_Name<<endl;
        cout<<"\n\t\t Your Ic Number is :"<<Ic_Number<<endl;
        cout<<"\n\t\t Your Come Back Time today is :"<<Come_Back_Time<<endl;

        if (Come_Back_Time <= 17.00)
        {
            cout<<"\n\t\t You are :Early"<<endl;
        }
        else
        {
            cout<<"\n\t\t You are :Late"<<endl;
        }
        
        while (a!=1234)
            cout<<"Try again"<<endl;
    }
}


Now - it can be seen that there is a do-while loop which starts on line 14 and ends on line 46. But there is no "while" at line 46.

It should be something like this:
1
2
3
4
do 
{
    // some code 
} while(condition);


Also lines 44-45 are a while loop which controls a single cout statement . This is probably not what was intended.
Last edited on
Topic archived. No new replies allowed.