Thread: output of characters

  1. #1
    Registered User deleeuw's Avatar
    Join Date
    Aug 2001
    Posts
    31

    Post output of characters

    hey all,
    I'm working on a geneolgoical program where we are coding relatives based on gender and generation, where at the command prompt f for female or m for male is ntered, after which, one has the option to continue (i.e. for the next generation). At the end, the entries appear as a number.

    For example, a man's mother's mother would be 100.

    Here's what I have so far:

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

    main()
    {
    int N=0;
    int gen [N];
    char x;
    char m;
    char f;

    top:
    N=N+1;
    cout<<"\nmale or female? m or f\n";
    cin>>x;
    if (x=='m'){
    char
    gen [N]=1;
    cin
    }
    else {
    gen[N]=0;
    }
    cout<<"Next generation? y or n ";
    char a;
    cin>>a;
    char y;
    char n;
    if (a=='y'){
    goto top;
    }
    else
    cout<<"\n";
    for (int i=0; i<N; ++i)
    cout<<gen;
    }

    the problem that I'm having is that it will indeed give a string of numbers, the length of which is correct, but it merely repeats the LAST entry.
    For example, if I input m, m, f, f, I should get 1100, but instead
    I get 0000.

    I'm sorry if I haven't explained it very clearly, but I would appreicate any help.

    777

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    main()
    {
    int N=0;
    int gen [N];
    ////an array of 0 elements??????? declare N
    //constant before entering main and make it greater
    // than zero maxvalue you can expect
    //arrays cannot grow once they are initialized unless
    //you use pointers and the word new
    //I suggest to look at using a while, do while or for
    // loop to replace the goto

    char m;
    char f;

    top:
    N=N+1;
    cout<<"\nmale or female? m or f\n";
    cin>>x;
    if (x=='m'){
    char
    gen [N]=1;
    cin
    }
    else {
    gen[N]=0;
    }
    cout<<"Next generation? y or n ";
    char a;
    cin>>a;
    char y;
    char n;
    if (a=='y'){
    goto top;
    }
    else
    cout<<"\n";
    for (int i=0; i<N; ++i)
    cout<<gen; //change this to gen[i]
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  4. Strange characters in output Need Help ASAP
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2003, 06:35 PM
  5. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM