Thread: Help - Creating a Graph in C++

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

    Help - Creating a Graph in C++

    Hey community, my name's Zach.

    I am currently trying to create a project that enables me to calculate the % chance of hitting a specific square on a graph, depending on the projectile used.

    ~The Problem~
    I can do most of it but, I do not necessarily know where to start when it comes to actually creating the graph to have points plotted on? Can anybody tell me or point me in the right direction on how to figure this out?


    I looked on the internet a lot but no tutorial is really showing me anything that I can understand and then translate into a program.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Are you talking about a visual representation "plotted" on screen - in which case, you need to tell us which OS and compiler you're using.

    Or are you just looking for a data structure to store the results of targets and hits, say
    Code:
    int grid[10][10] = {
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },   
    };
    
    if ( grid[rand()%10][rand()%10] == 2 ) {
      printf("You hit my battleship!\n");
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    As Salem asks - what is the problem you are having? Using actual graphics is the obstacle? Or is it that you cannot yet figure a way of representing it in the computer memory? You should post your code - you say you can do most of it - so where do you get stopped?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Graph - Help!! :(
    By Zeldic in forum C++ Programming
    Replies: 6
    Last Post: 06-02-2010, 08:15 AM
  2. graph.h
    By spime in forum C Programming
    Replies: 10
    Last Post: 11-04-2008, 02:22 PM
  3. Graph
    By johnthomas in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2008, 11:38 AM
  4. Graph
    By fkheng in forum C Programming
    Replies: 8
    Last Post: 07-05-2003, 10:57 PM
  5. Bar graph
    By robjules in forum C++ Programming
    Replies: 3
    Last Post: 11-28-2001, 10:55 PM