Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Having trouble graphing in C++

  1. Apr 30, 2007 #1
    hey. i want to graph a projectile motion. i got the code of a sine wave but the x and y axis' are in the opposite sides. i want the curve to look like a projectile with the curve facing down. thanx. heres my code

    #include <iostream.h>
    #include <iomanip.h>
    #include <math.h>
    #include <cstdlib>

    void main()
    const float PI = 3.1416;
    const int STEPS = 16;
    const int SIZE = 15;
    const char STAR = '*';
    const char BLANK = ' ';
    int step;
    float angle;
    int indent;

    char again = 'n';


    cout << " SINEWAVE SAMPLE PROGRAM\n\n";
    angle = 0;
    indent = 0;

    for (step=0; step<=STEPS; step++)
    angle = (PI) * step / STEPS;
    indent = 5.5 + SIZE + SIZE * sin(angle);
    cout << setiosflags(ios::showpoint|ios::fixed)
    << setw(6) << angle/PI << "pi";
    for (int i = 1; i <= indent; i++)
    cout << BLANK;
    cout << STAR << "\n";
    cout << "Angle\n(radians)\n\n";

    cout << "Do you want to run the program again (y/n) ??? ";
    cin >> again;
    while ((again == 'y') || (again == 'Y'));
  2. jcsd
  3. May 1, 2007 #2
    u should have just put this in the other thread you started.

    what languages/software do you have at your disposal?

    Excel? Matlab? Maple? If you can write to a file you can use these programs.

    if you need to use C/C++ i suggest looking into either opengl/glut or opengl/SDL, the former being the easier of the two to learn. I believe you posted that u were using MSVC, in which case you can use MFC or forms or GDI. GDI is easy to use if you perform piecewise approximations of your curve with the line or lots of points. Else i'd look into using opengl/glut.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook