Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using function prototypes with a loop

Posted on 1998-04-22
5
Medium Priority
?
244 Views
Last Modified: 2010-04-15
I am writing a program to use global function prototypes. So far I have the functions working the way I want but
the last last part of the loop will not print the letter and terminate the program. Can any body help? I can not use
global variables and goto statements. I have six letters to let the user pick from,('A/a','B/b','P/p','X/x','y/y',or'Q/q')
once the letter is chosen, it prints out as an upper case version using the lower case letter. If the letter 'Q' or 'q'
is used it is supposed to print out the upper case version and terminate. This is where I am having the problem.
The program starts:
#include <stdio.h>
void prn_A(void);
void prn_B(void);
void prn_P(void);
void prn_X(void);
void prn_Y(void);
void prn_Q(void);
void main ()
{
  char ch;
      do
      { printf("Enter one of the following upper or lower case letters, A/a, B/b, P/p, X/x, Y/y or (Q/q to quit)"  );
                        flushall();
                        ch=getchar();
            if(ch=='Q' || ch=='q')
                continue;
                else if(ch=="A' || ch=='a')
                           prn_A();
                else if(ch=='B' || ch=='b')
                           prn_B();
                else if(ch=='P' || ch=='p')
                           prn_P();
                else if(ch=='X' || ch=='x')
                           prn_X();
                else if(ch=='Y' || ch=='y')
                           prn_Y();
     }
       while(ch!='Q' || ch!='q');
                 prn_Q();
}
       void prn_A(void)
       {
         printf("This is where it prints the upper case version of 'A' using lower case 'a'");
       }
       void prn_B(void)
       {
        printf("This is where it prints the upper case version of 'B' using lower case 'b'");
       }
       void prn_P(void)
       {
        printf("This is where it prints the upper case version of 'P' using lower case 'p'");
       }
And so on, the remaining letters are the same. As I said, everything works up to the point where I try to print
the letter 'Q' and terminate the program. I am new at this so please have patience with my programing.            
0
Comment
Question by:cstudent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:cstudent
ID: 1252061
Edited text of question
0
 
LVL 3

Accepted Solution

by:
q2guo earned 200 total points
ID: 1252062
I think line
while(ch!='Q' || ch!='q');

should be
while(ch !='Q' && ch !='q');
0
 

Author Comment

by:cstudent
ID: 1252063
Thanks for the info. It worked just fine. My only question is why the && and not the || ?
Don't both conditions have to be true using && ? Thanks again. cstudent
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1252064
Well, think about it

when you say while(ch != 'Q' || ch != 'q')
you are telling the computer you want to stay in the
loop if ch is not Q or ch is not q.  Since ch will
never be Q and q at the same time.  So, the loop continues for
ever.
0
 

Author Comment

by:cstudent
ID: 1252065
g2guo,
Thanks for the explanation. It helped a lot.
                                        cstudent
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question