Can someone please help me solve the following problems for my mini project? Your help will be highly appriciated...
1. The function frontpage(name) can't be linked to the other 2 functions.
2. If user mis-enter a character for switch case, a infinite loop will occur.(same case happened for cin>>number_resistor in my project)
Code:
void resistor_knowledge(void frontpage(char name[50])){
system("color 4E");
ifstream resistor_file("resistor.txt");
char k_resistor[max_letter];
for (int size=0; size<=20; size++){
resistor_file.getline(k_resistor,max_letter);
cout<<k_resistor;
cout<<"\n\nPRESS ANYKEY TO RETURN TO MAIN MENU.";
getch();
frontpage(name);
}
}
void capacitor_knowledge(void frontpage(char name[50])){
system("color 4E");
char k_capacitor[max_letter];
ifstream capacitor_file("capacitor.txt");
for (int size=0; size<=20; size++){
capacitor_file.getline(k_capacitor,max_letter);
cout<<k_capacitor;
cout<<"\n\nPRESS ANYKEY TO RETURN TO MAIN MENU.";
getch();
frontpage(name);
}
}
void frontpage(char name[50]){ int choice,x;
repeat_main:
system ("COLOR 3A");
cout<<"\n Hello, "<<name<<".\n Welcome to this CIRCUIT PROGRAM!!\n\n";
printf(" 4.Resistance in a circuit\n 5.Capacitor in a circuit\n ");
cin>>choice;
system("CLS");
switch (choice){
case 1:
resistor_knowledge();
break;
case 2:
capacitor_knowledge();
break;
default:
{
cout<<"\n\n\n INVALID INPUT!!\n\n ENTER A VALID INPUT PLEASE!!!";
time(x=3);
system("CLS");
goto repeat_main;
}
}
}
int main(){
char name[50];
cout<<"Please enter your name:";
cin.getline(name,50);
system("CLS");
frontpage(name);