#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
#define MAX 50
char name[MAX][30];
char exper[MAX][20];
int idno[MAX];
char jlvl[MAX];
float mnthsr[MAX];
double annusr[MAX];
int cons[MAX];
int x;
char yesno1;
void main()
{
clrscr();
x=1;
restart1:
if(x<=50)
{
if (cons[x]!=0)
x++;
else
{
cout << "\n\nFill up the Information needed to proceed:\n\nName:\t";
gets(name[x]);
cout << "\nExpertise:\t";
gets(exper[x]);
cout << "\nIdentification Number:\t";
scanf("%d",&idno[x]);
cout << "\nJob level: (Please select from 'A', 'B', 'C', 'D')\t";
jlvl[x] = getch();
cout << "\nMonthly Salary Rate:";
scanf("%f",&mnthsr[x]);
cout << "\nYour Annual Salary Rate is:\t";
switch(jlvl[x])
{
case'a':{
annusr[x]=(mnthsr[x])*12;
}
case'b':{
annusr[x]=(mnthsr[x])*13;
}
case'c':{
annusr[x]=(mnthsr[x])*14;
case'd':{
annusr[x]=(mnthsr[x])*15;
}
default:
{
cout << " ";
}
}
printf("%.2lf",annusr[x]);
cons[x]=1;
}
cout << "\n\nDo you want to do it again? y/n:\t";
yesno1 = getch();
switch(yesno1)
{
case'y':
{
goto restart1;
}
default:
{
cout << "Press any key to continue:";
}
}
getch();
}
}
}
im using turbo c++ as compiler so please understand :D
it is only the first part of my program so there are 50 arrays because we are asked to hold 50 different "consultants" per instance.
anyways when my program asks for the user to restart the program, pressing y should make it return to the inputting again but it didnt. please help T_T.
You don't need global variables.. put them inside main(). And use int main() as opposed to void main().
I'm not completely sure but when you goto restart1; variable x is still left the same it is so since the redeclaration to make it 1 is above the restart1: tag. That means if x is left at over 50 the rest of that if (...) { } doesn't execute. I think you can solve this by placing restart1: at the beginning of main().
P.S. Functions might be better and neater for a program like this, as opposed to goto ... tags.
Prompt the user for the number of consultants for each consultant, prompt the user to enter values for each of the ff:
1. NAME (30 characters)
2.EXPERTISE (20 characters)
3. IDENTIFICATION NUMBER (integer)
4.JOB LEVEL (possible values allowed are 'A', 'B', 'C', 'D')
5. MONTHLY SALARY RATE (float with 2 decimal places)
6. ANNUAL SALARY RATE (double with 2 decimal places, computation depends on the job level)
for job level 'A' 12-month pay
for job level 'B' 13-month pay
for job level 'C' 14-month pay
for job level 'D' 15-month pay
Each element should be stored in arrays.
Assume a maximum of 50 consultants forthis program. Display the data in table format after the user entered the last consultant.
SAMPLE MENU:
[1] ADD NEW CONSULTANT
[2] UPDATE CONSULTANT RECORD
[3] DISPLAY CONSULTANT LIST
[4] QUIT
For the 2nd choice menu is:
1. NAME
2. ID NUMBER
If the input is 1, prompt the user for the consultant name to be updated. If choice 2, prompt user for ID no. of the consultant.
If the consultant is not yet in the list, then inform the user that such consultant cannot be found in the list. Otherwise, display the complete record of the matching consultant in the list. then for each field, ask the user if he/she wants to update that field. If yes then prompt the user for the new value of the field. Control goes back to the main menu.
For the third choice, display out the data in table format as below:
NAME EXPERTISE ID NO. JOB LEVEL MONTHLYRATE
1 MANUEL DIAZ COMPT SPECIALIST 476 D 845.56
2 ELENA MARQUEZ SOUND EDITOR 596 b 1745.23
so i need global variable to be able to call them @ the following functions, that code i posted is just option no.1, just made it main() so i can debug it before anything,
2.why should i put int main instead of void main? just wanna know thanks.
3.the program must allow 50 consultants stored for each instance, without using any .txt file so i used if(cons[x]>=50) so i can call con[2],con[3] and so on for the search function for the 2nd option by using arrays.
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
#define MAX 50
char name[MAX][30];
char exper[MAX][20];
int idno[MAX];
char jlvl[MAX];
float mnthsr[MAX];
double annusr[MAX];
int cons[MAX];
int getInfo()
{
int x;
char yesno1;
clrscr();
x=1;
restart1:
if(x<=50)
{
if (cons[x]!=0)
{
x++;
cons[x]=1;
}
else
{
cout << "\n\nFill up the Information needed to proceed:\n\nName:\t";
gets(name[x]);
cout << "\nExpertise:\t";
gets(exper[x]);
cout << "\nIdentification Number:\t";
scanf("%d",&idno[x]);
cout << "\nJob level: (Please select from 'A', 'B', 'C', 'D')\t";
jlvl[x] = getch();
cout << "\nMonthly Salary Rate:";
scanf("%f",&mnthsr[x]);
cout << "\nYour Annual Salary Rate is:\t";
switch(jlvl[x])
{
case'a':{
annusr[x]=(mnthsr[x])*12;
}
case'b':{
annusr[x]=(mnthsr[x])*13;
}
case'c':{
annusr[x]=(mnthsr[x])*14;
case'd':{
annusr[x]=(mnthsr[x])*15;
}
default:
{
cout << " ";
}
}
printf("%.2lf",annusr[x]);
}
cout << "\n\nDo you want to do it again? y/n:\t";
yesno1 = getch();
switch(yesno1)
{
case'y':
{
goto restart1;
}
default:
{
cout << "\nPress any key to continue:";
}
}
getch();
}
}
return 0;
}
int main(int menures)
{
resmenu:
clrscr();
cout << "\n\n\n\n\n\t" << "[1]\tADD NEW CONSULTANT";
cout << "\n\t" << "[2]\tUPDATE CONSULTANT RECORD";
cout << "\n\t" << "[3]\tDISPLAY CONSULTANT LIST";
cout << "\n\t" << "[4]\tEXIT";
cout << "\n\t" << "\n\nYour Choice:\t";
cin >> menures;
switch(menures)
{
case 1:
{
getInfo();
goto resmenu;
}
case 2:
{
goto resmenu;
}
case 3: {
goto resmenu;
}
case 4:
{
goto exit;
}
}
exit:
return (menures);
}
update!
now my got it all PARTIALLY solved thanks to the replies, anyway now my problem is,
when i restart adding Infos, it now skips the gets(name[x]);
im quite clueless how to solve this since ive already flatten out all possibilities starting from array errors.