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
Solved

How to get REJECTED to display?

Posted on 1997-12-08
1
184 Views
Last Modified: 2010-04-02
This program suppose to allow the user to enter a social security nummber.
If the number matches on in the list it will display "ACCEPTED."  If it
doesn't match it will display "REJECTED".  To end the program the user
has to enter 000000000.

My problem with this program is when a social security number that does
not match is entered, the program displays nothing.  What could be the
problem.

Everything else works fine.



This is my code:

#include <stdio.h>
#include <stdlib.h>

void main()

{
long ssn[8] = {118456835,203658739,444545555,513587652,725468190,7967355113,861490579,921424023};
char buffer[25];
long l;
int x;

do
{
printf("\n\nEnter 000000000 to end program.");
printf("\nEnter Social Security Number ===>");
gets(buffer);

l=atol(buffer);

for(x=0; x<=7; x++)
      {

      if(ssn[x]==l)
            printf("\nACCEPTED");
       }

if(ssn[x]==000000000)
      printf("\nSearch Completed.");

else
//            if(l!=ssn[x])
            printf("\nREJECTED");
 
      }

while(l!=000000000);
}
0
Comment
Question by:lawrencej
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1256557
This section of your code will never be true:

if(ssn[x]==000000000)
printf("\nSearch Completed.");

Instead you should modify your code to be something like

int found = 0;
for(x=0; x<=7; x++)
{
  if(ssn[x]==l)
  {
    printf("\nACCEPTED");
    found = 1;
  }
}

if (found == 0)
  printf("\nRejected");


0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

809 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