Thread: telecomunication program - pb with how to verifie that a nbr is included in an array-

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    telecomunication program - pb with how to verifie that a nbr is included in an array-

    I've been asked to write a program for which :

    You are asked to write a C program for telecommunication company, the program 1- asks the user to enter his number.
    2- displays which operator he is using.
    3- asks him if: -he wants to buy credit ( in this case asks for the amount of money).
    - he wants to talk to an agent ( and keeps talking until he presses 1 to hung out)
    - he wants to send a default message for a friend who uses the same operator ( he should enter the number of the friend and the program verifies if it is the same operator, and displays a choice of four default messages [you are free to choose default messages] )

    -he wants to exit.
    The user should be able to make diffrent operations without closing the program, whenever an operation is finished , the programs goes back to the main menu.The program only exits when the user chooses “exit” from the menu.



    my pbs were : 1-I don't know how to ( make the compiler verifie if it is the same operator )

    2- while I am using the ( do while ) it keeps reapiting the " enter ur number " and when I switched it below it keeps reapiting only the 1st condition




    this is my program if anyone could help me :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int number,n,friendnumber,amountofmoney;
    int operatorr;
    
    int main()
    {
    do
        {
        printf("Enter your number please :\n");
        scanf("%d",&number);
        printf("You are now using the operator: 123\n");
    
        printf("press 2 to choose how to buy and 3 to talk to an agent and 1 to send a default msg and 0 if you want to exit ");
        scanf("%d",&n);
    
    
            if(n==2)
        {
    
              printf("\nyou will buy credit, enter your amount of money :");
              scanf("%d",&amountofmoney);
    
        }
        else if  (n==3)
        {
            printf("\nyou are now talking to an agent press 1 to hung out");
            scanf("%d",&n);
        }
        else if (n==1)
        {
            printf("\nif you want to send a default message to a friend enter his number : ");
            scanf("%d",&friendnumber);
            if (friendnumber[&number])
            {
                printf("Hi, how are you ?");
                printf("\nI need you in emergency");
                printf("\nlet's meet tonight");
                printf("\nI will be there ASAP");
            }
           else
           printf("\nyou're user is not using the same operator as you ");
        }
        }
        while (n!=0);
    
    return 0;
    }

  2. #2
    Registered User Jeet's Avatar
    Join Date
    Jan 2013
    Posts
    7
    You should take a look here : Switch Case in C and C++ - Cprogramming.com
    Also make use of functions, refactor your code.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    In the title you mention finding if a number is included in an array, which is probably the way to solve your problem. However, in the code you gave us, there is no array definition. You need to define the array first before you can try to find out if a number is included in it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do cpp Files get Included Automatically in VS?
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 05-20-2009, 04:12 PM
  2. Hangman Help - Code included
    By darren78 in forum C Programming
    Replies: 3
    Last Post: 02-17-2009, 09:35 AM
  3. Replies: 15
    Last Post: 05-17-2007, 03:10 PM
  4. Nibbles (src included)
    By Perspective in forum Game Programming
    Replies: 7
    Last Post: 08-02-2004, 12:35 PM
  5. problem(program error) with bubble sort(code included)
    By choykawairicky in forum C++ Programming
    Replies: 6
    Last Post: 05-16-2004, 08:54 AM