Help!!!questions about a circuit program..

This is a discussion on Help!!!questions about a circuit program.. within the C++ Programming forums, part of the General Programming Boards category; Can someone please help me solve the following problems for my mini project? Your help will be highly appriciated... 1. ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    2

    Help!!!questions about a circuit program..

    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);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,847
    First, delete lines 10 and 23.
    You'd get back to frontpage() simply by returning - not by calling it recursively.

    Then replace your goto repeat_main; with a while loop.

    > time(x=3);
    What's this supposed to do?

    Also, get rid of all those system(cls) and system(color) calls until the whole thing is working.
    They're just candy distraction until the program is working.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    2
    Returning??how to return??can u give me an example?thanks...
    The time(x=3) is just another function which i didn't include when copying.
    & thanks again for your suggestion...i'll remove those things until my program run properly^.<

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Circuit Reliability program
    By Northstar in forum C Programming
    Replies: 1
    Last Post: 12-04-2007, 02:01 AM
  2. C Programming for LED circuit
    By vivharv in forum C Programming
    Replies: 4
    Last Post: 09-18-2007, 05:34 AM
  3. eulers circuit
    By zarganah in forum C++ Programming
    Replies: 4
    Last Post: 11-15-2004, 06:25 PM
  4. Circuit Boards - probably a dumb question
    By sean in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-09-2003, 06:44 PM
  5. circuit
    By theOracle in forum C++ Programming
    Replies: 13
    Last Post: 05-18-2003, 08:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21