deceleration terminated and

I am getting possible use of cChoice before definition and declaration terminated incorrectly
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>

void main()
{
char userId[10],passwrd[10];
char uoid[] = "MIS",opasswrd[] = "123";
int chances = 3;
char cChoice;

while (chances)
{
printf("Enter User ID -> ");
scanf("%s", userId);
printf("\n");
printf("Enter Your Password -> ");
scanf("%s", passwrd);

if (strcmp(uoid, userId) == 0 && strcmp(passwrd, opasswrd) == 0)
{
printf("Correct User Id And Password\n");
break;
}
else
{
printf("Invalid User Id And Password\n\n");
chances--;

if(!chances)
{
printf("You have no more chances...\n");
printf("Do you want to register y/n -> ");

printf("\n");

if(cChoice=='Y'||cChoice=='y')
{
printf("Enter your new ID -> ");
scanf("%s",uoid);
printf("Enter your new PW -> ");
scanf("%s",opasswrd);

chances = 3;
}
}
}
}

clrscr();


}
{
char choice;
char c[50];
char id[50];
char age[50];
char last[100];
char first[100];
char dep[50];
char add[50];

b:
clrscr();
printf("=====PROGRAM MENU=====");
printf("\n\n[1] = CIRCLE AREA");
printf("\n[2] = RECTANGLE AREA");
printf("\n[3] = TRIANGLE AREA");
printf("\n[4] = LAST GRADE");
printf("\n[5] = LETTER GRADE");
printf("\n[6] = FACTORIAL");
printf("\n[7] = PRINTING");
printf("\n[8] = Exit Program");
printf("\n\nChoice : ");
scanf("%d",&choice);
switch (choice)
{
case 1:
clrscr();
FILE * f;

f=fopen("test.txt","r+");
if(f==NULL){
printf("No Database");
exit(1);
}

getch();
}
Last edited on
Line 7: main() must be type int

Line 12: cChoice is an uninitialized variable (garbage).

Line 39: You test cChoice, but cChoice is an uninitialized variable.

Line 54-55: What are the {} for?

Line 89: You're missing a } terminating the switch statement.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
okay my problem at line 57 and 55 if I remove { or } its says many errors like obsolete error


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
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<iostream>
#include<stdlib.h>
 
int main()
{
    char userId[10],passwrd[10];
    char uoid[] = "MIS",opasswrd[] = "123";
    int chances = 3;
 
 
    while (chances)
    {
        printf("Enter User ID -> ");
        scanf("%s", userId);
        printf("\n");
        printf("Enter Your Password -> ");
        scanf("%s", passwrd);
 
        if (strcmp(uoid, userId) == 0 && strcmp(passwrd, opasswrd) == 0)
        {
            printf("Correct User Id And Password\n");
            break;
        }
        else
        {
            printf("Invalid User Id And Password\n\n");
            chances--;
 
            if(!chances)
            {
                printf("You have no more chances...\n");
                printf("Do you want to register y/n -> ");
 
                printf("\n");
 
 
                {
                    printf("Enter your new ID -> ");
                    scanf("%s",uoid);
                    printf("Enter your new PW -> ");
                    scanf("%s",opasswrd);
 
                    chances = 3;
                }
            }
        }
    }
 
    clrscr();
 
 
}
 
{
    char choice;
    char c[50];
    char id[50];
    char age[50];
    char last[100];
    char first[100];
    char dep[50];
    char add[50];
 
b:
    clrscr();
    printf("=====PROGRAM MENU=====");
    printf("\n\n[1] = CIRCLE AREA");
    printf("\n[2] = RECTANGLE AREA");
    printf("\n[3] = TRIANGLE AREA");
    printf("\n[4] = LAST GRADE");
    printf("\n[5] = LETTER GRADE");
    printf("\n[6] = FACTORIAL");
    printf("\n[7] = PRINTING");
   printf("\n[8] = Exit Program");
    printf("\n\nChoice : ");
    scanf("%d",&choice);
    switch (choice)
    {
    case 1:
        clrscr();
        FILE * f;
 
        f=fopen("test.txt","r+");
        if(f==NULL){
            printf("No Database");
            exit(1);
}
 
    getch();
}
Lines 55-57: There is still no reason for the }{ here.

Line 91: You're still missing a } for the switch statement. Note that the } at line 90 terminates the if statement, not the switch statement.

This compiles with only warnings:
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
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<iostream>
#include<stdlib.h>
 
int main()
{
    char userId[10],passwrd[10];
    char uoid[] = "MIS",opasswrd[] = "123";
    int chances = 3;
 
 
    while (chances)
    {
        printf("Enter User ID -> ");
        scanf("%s", userId);
        printf("\n");
        printf("Enter Your Password -> ");
        scanf("%s", passwrd);
 
        if (strcmp(uoid, userId) == 0 && strcmp(passwrd, opasswrd) == 0)
        {
            printf("Correct User Id And Password\n");
            break;
        }
        else
        {
            printf("Invalid User Id And Password\n\n");
            chances--;
 
            if(!chances)
            {
                printf("You have no more chances...\n");
                printf("Do you want to register y/n -> ");
 
                printf("\n");
 
 
                {
                    printf("Enter your new ID -> ");
                    scanf("%s",uoid);
                    printf("Enter your new PW -> ");
                    scanf("%s",opasswrd);
 
                    chances = 3;
                }
            }
        }
    }   // end while
 
//    clrscr();
 
    char choice;
 
//  clrscr();
    printf("=====PROGRAM MENU=====");
    printf("\n\n[1] = CIRCLE AREA");
    printf("\n[2] = RECTANGLE AREA");
    printf("\n[3] = TRIANGLE AREA");
    printf("\n[4] = LAST GRADE");
    printf("\n[5] = LETTER GRADE");
    printf("\n[6] = FACTORIAL");
    printf("\n[7] = PRINTING");
   printf("\n[8] = Exit Program");
    printf("\n\nChoice : ");
    scanf("%d",&choice);
    switch (choice)
    {
    case 1:
//        clrscr();
        FILE * f;
 
        f=fopen("test.txt","r+");
        if(f==NULL)
        {   printf("No Database");
            exit(1);
        }  // end if
    }  // end switch
    getch();
}

Last edited on
Topic archived. No new replies allowed.