another problem

This is a discussion on another problem within the C Programming forums, part of the General Programming Boards category; Right, i sorted my parse error with some much appreciated help, so cheers. I have another problem. Code: do{ printf("welcome ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    16

    another problem

    Right, i sorted my parse error with some much appreciated help, so cheers. I have another problem.
    Code:
    do{
     printf("welcome to the Tee, Pi, Min loss pad resistor calculation program");
     printf("\n\n\n");
     printf("Choose your desired network\n\n");
     printf("enter T=Tee network; P=Pi network; M=Min loss; Q=Quit program\n");
     choice=getchar();
     choice=toupper(choice);
     switch(choice) {
    
    
    
    case 'T': {   
    	printf("Choose type of Tee network");
    	printf("\n\n");
    	printf("Enter B=Balanced; U=Unblanced\n");
    	type=getchar();
     	 type=toupper(type);
    
    	switch(type){
    				
    case 'U': {
    			
    	printf("enter a value for the input impeadence\n");scanf("%f",&Z);
                    printf("enter a value for the output impeadence\n");scanf("%f",&Z2);
    				printf("enter a value for the Loss\n");scanf("%f",&l);
    				
    				N=pow(10,l/10);
    				R3=2*sqrt(N*Z*Z2)/(N-1);
    				printf("the value of R3 is %f\n",R3);
    				R2=(Z2*(N+1)/(N-1))-R3;
    				printf("the value of R2 is %f\n",R2);
    				R1=(Z*(N+1)/(N-1))-R3;
    				printf("the value of R1 is %f\n",R1);
    			
    				break;}
    		
    				case 'B': {
    			
    				printf("enter a value for the input impeadence\n");scanf("%f",&Z);
    				printf("enter a value for the output impeadence\n");scanf("%f",&Z2);
    				printf("enter a value for the Loss\n");scanf("%f",&l);
    				
    				N=pow(10,l/10);
    				R3=2*sqrt(N*Z*Z2)/(N-1);
    				printf("the value of R3 is %f\n",R3);
    				R2=(Z2*(N+1)/(N-1))-R3;
    				printf("the value of R2 is %f\n",R2);
    				R1=(Z*(N+1)/(N-1))-R3;
    				printf("the value of R1 is %f\n",R1);
    				break;}
    				
    					break;}
    			
    
    
    case 'P': {
    	
    	printf("Choose type of Pi network");
    	printf("\n\n");
    	printf("Enter B=Balanced; U=Unblanced\n");
    	type=getchar();
    	type=toupper(type);
    	}
    	switch(type){
    I know that came out pretty much unreadable, but when i choose T from the 1st menu it also shows the options for not only Tee, but Pi too. Basically it prints out case 'T' and case 'P'. I need some kind of loop to stop it doing this but am not sure how to put one in or which one to use. I dont think i explained it very well either.

    Any help/ideas/micky taking would be much appreciated as i am at the end of my very short rope as regards this!

    Cheers

    Andy

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I know that came out pretty much unreadable
    Yes, it did. If you use spaces instead of tabs and a good intention style then that won't happen.

    >it also shows the options for not only Tee, but Pi too
    Make sure that you are breaking out of the switch when you expected to. Most likely you're missing a break statement. I would check to see where it is, but the thought of trying to parse your code scares me.
    My best code is written with the delete key.

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    I know that came out pretty much unreadable

    That's the problem
    Code:
    choice=getchar();
    choice=toupper(choice);
    switch(choice) 
    {
      case 'T': 
      {   
        type=getchar();
        type=toupper(type);
    
        switch(type)
        {
          case 'U': 
          {
            break;
          }
    
          case 'B': 
          {
            break;
          }
    		
          break;
        }
    
        case 'P': 
        {
          type=getchar();
          type=toupper(type);
        }
    
        switch(type)
        {
    See what's wrong?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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