Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: my little project  (Read 12657 times)

0 Members and 1 Guest are viewing this topic.

airyoubreathe

    Topic Starter


    Rookie
    my little project
    « on: December 17, 2009, 06:06:10 PM »
    When I was a kid, my uncle taught me c++, in the last couple months I got interested in it again, I have read a couple online tutorials and feel comfortable with console applications now, I am now working on a rather simple project, i am trying to compare a picture of a 10 by 10 d and a 10 by 10 g, for some reason when I run it, after I enter what i want examined it says theres an error and it must shut down, its that little box where you can send an error report to microsoft, i narrowed it down to line 77 (youll see it in a minute, ill put a comment next to it) thankyou, if you need my computers info ill post it,

    Code: [Select]
    #include <iostream>
    #include <stdlib>
    #include <string>
    #include <conio.h>

    using namespace std;

    string d1[10];      // pic 1 of d
    string g1[10];      // pic 1 of g
    string in[10];      // what is entered
    float dc;           // likeliness of d
    float gc;           // likeliness of g
    float dpr;          // percentage to be d
    float gpr;          // percentage to be g
    float tpr;          // what times d/g to be 100
    int cdt;            // tests if it is already to be a part of d
    int np;             // np = n plus nm = n minus, same for x
    int nm;
    int xp;
    int xm;

    void dlib()         // defines library
    {
    d1[0] = "g@@ggggggg";
    d1[1] = "g@g@gggggg";
    d1[2] = "g@gg@ggggg";
    d1[3] = "g@ggg@gggg";
    d1[4] = "g@gggg@ggg";
    d1[5] = "g@gggg@ggg";
    d1[6] = "g@ggg@gggg";
    d1[7] = "g@gg@ggggg";
    d1[8] = "g@g@gggggg";
    d1[9] = "g@@ggggggg";
    g1[0] = "g@@@@@@@gg";
    g1[1] = "g@ggggg@gg";
    g1[2] = "g@gggggggg";
    g1[3] = "g@gggggggg";
    g1[4] = "g@gggg@@@g";
    g1[5] = "gg@gggg@gg";
    g1[6] = "ggg@ggg@gg";
    g1[7] = "gggg@@@ggg";
    g1[8] = "gggggggggg";
    g1[9] = "gggggggggg";

    }

    #define CMP if (in[np][x] == d1[np][x]) { \
    dc++;\
    cdt++;\
    }\
    else if (in[nm][x] == d1[nm][x]) {\
    dc++;\
    cdt++;\
    }\
    else if (in[n][xp] == d1[n][xp]) {\
    dc++;\
    cdt++;\
    }\
    else if (in[n][xm] == d1[n][xm]) {\
    dc++;\
    cdt++;\
    }\
    else {\
    dc++;\
    }\

    void perc()         // calculates what it is
    {
    for (int n=9; n>=0; n--) {
    for (int x=9; x>=0; x--) {
    np = n + 1;
    nm = n - 1;
    system("PAUSE"); // 1
    xp = x + 1;
    xm = x - 1;
    system("PAUSE"); // 2
    if (in[n][x] == d1[n][x]) {          // this is it!!!
    system("PAUSE"); // 3
    CMP
    }

    else if (in[n][x] == g1[n][x]) {
    if (cdt == 0) {
    if (in[n][x] == g1[n][x]) {
    gc++;
    }
    }
    }
    cdt = 0;
    system("PAUSE");  // 6
    }
    }
    tpr = 100/dc;   // caculates percentage of d and g
    dpr = 100 - (gc * tpr);
    tpr = 100/gc;
    gpr = 100 - (dc * tpr);
    }

    int main()
    {
    cdt = 0;
    dlib();
    cout << "hello, enter in what you would like to be tested, please only use '@' and 'g'" << endl;
    for (int p=0; p<10; p++) {
    cin >> in[p];
    }
    perc();
    system("PAUSE");
    cout << "likeliness to be d: " << dpr << endl << "likeliness to be g: " << gpr << endl;
    getch();
    return 0;
    }

    Treval



      Hopeful

      Thanked: 14
      Re: my little project
      « Reply #1 on: January 21, 2010, 11:42:26 AM »
      Don't know why your if line in #define at line 47 is marked green:
      http://pastebin.com/d7742d53f

      Might have to do with that it gets stuck.
      Reasons I think of:

      1) Array elements not defined
      2) One or both array elements referred to don't exist
      3) ArrayIndexes out of bounds
      4) Add a sort of break statement?

      What is CMP?



      kpac

      • Web moderator


      • Hacker

      • kpac®
      • Thanked: 184
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: my little project
      « Reply #2 on: January 21, 2010, 11:49:31 AM »
      Why are you posting in old topics?

      Treval



        Hopeful

        Thanked: 14
        Re: my little project
        « Reply #3 on: January 21, 2010, 11:55:23 AM »
        Because people might be hoping to get them answered, have this thread on a bookmark, like me.
        You never know.

        kpac

        • Web moderator


        • Hacker

        • kpac®
        • Thanked: 184
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 7
        Re: my little project
        « Reply #4 on: January 21, 2010, 11:58:27 AM »
        Well usually if there's no response within a month, we don't reply at all.

        Treval



          Hopeful

          Thanked: 14
          Re: my little project
          « Reply #5 on: January 21, 2010, 12:09:54 PM »
          Maybe not you, but I will.
          I don't like to assume things like the rest of the sheep.

          kpac

          • Web moderator


          • Hacker

          • kpac®
          • Thanked: 184
            • Yes
            • Yes
            • Yes
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: my little project
          « Reply #6 on: January 21, 2010, 12:22:56 PM »
          Quote
          Maybe not you, but I will.
          Fine, be different. But the threads will just be locked.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: my little project
          « Reply #7 on: January 21, 2010, 12:25:53 PM »
          Maybe not you, but I will.
          I don't like to assume things like the rest of the sheep.

          is that you, SpectateSwamp?
          I was trying to dereference Null Pointers before it was cool.

          Treval



            Hopeful

            Thanked: 14
            Re: my little project
            « Reply #8 on: January 21, 2010, 12:45:22 PM »
            *censored*, no.
            Look up my IP if you like.
            I am Treval.

            Salmon Trout

            • Guest
            Re: my little project
            « Reply #9 on: January 21, 2010, 02:32:43 PM »
            *censored*

            mind your language please

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: my little project
            « Reply #10 on: January 21, 2010, 02:44:46 PM »
            mind your language please
            This is a public forum with young members.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: my little project
            « Reply #11 on: January 22, 2010, 08:56:08 AM »
            hoisted by their own petard.
            I was trying to dereference Null Pointers before it was cool.

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: my little project
            « Reply #12 on: January 22, 2010, 08:12:03 PM »
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            Salmon Trout

            • Guest
            Re: my little project
            « Reply #13 on: January 23, 2010, 02:33:22 AM »
            Hoist with their own petard.

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: my little project
            « Reply #14 on: January 23, 2010, 07:36:43 AM »
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.