# How Can I Adjust My C++ Sine Wave Code to Simulate Projectile Motion?

• C/C++
In summary, the conversation discusses the topic of graphing projectile motion using various programming languages and software such as Excel, Matlab, Maple, and C/C++. The suggestion is made to use either OpenGL/GLUT or OpenGL/SDL for those using MSVC, and to use MFC, forms, or GDI for those using GDI.
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. here's 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';

do
{
system("cls");

cout << " SINEWAVE SAMPLE PROGRAM\n\n";
cin.get();
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)
<<setprecision(2)
<< setw(6) << angle/PI << "pi";
for (int i = 1; i <= indent; i++)
cout << BLANK;
cout << STAR << "\n";
}
cin.get();

system("cls");
cout << "Do you want to run the program again (y/n) ? ";
cin >> again;
}
while ((again == 'y') || (again == 'Y'));
return;
}

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.

Hi there,

Thank you for sharing your code. It looks like you are trying to graph a projectile motion using a sine wave. To make the curve face down, you can simply multiply the y-coordinate by -1 before plotting it. This will flip the curve upside down and make it look like a projectile motion.

Additionally, you can change the x-axis to represent time and the y-axis to represent the height of the projectile. This will make the graph more accurate and easier to understand.

I hope this helps. Keep practicing and experimenting with your code to improve your graphing skills in C++. Good luck!

## 1. Why am I having trouble graphing in C++?

There could be several reasons why you are having trouble graphing in C++. Some common reasons include incorrect syntax, incorrect data input, or a lack of understanding of the graphing functions in the C++ library you are using. It is important to carefully review your code and make sure you understand the concepts behind graphing in C++.

## 2. How do I graph in C++?

To graph in C++, you will need to use a library that supports graphing, such as the graphics.h library in the Turbo C++ compiler. You will also need to understand the basic concepts of graphing, such as plotting points and drawing lines. It is recommended to start with simple examples and work your way up to more complex graphs.

## 3. How do I plot multiple points on a graph in C++?

To plot multiple points on a graph in C++, you can use a loop to iterate through a set of coordinates and use the putpixel() function to plot each point. You can also use the lineto() function to draw lines between the points. It is important to make sure your coordinates are accurate and within the bounds of the graph.

## 4. How do I add labels and titles to my graph in C++?

You can add labels and titles to your graph in C++ by using the outtextxy() function to print text at specific coordinates on the graph. You can also use the settextstyle() function to change the font and style of the text. It is recommended to use variables to store your text and coordinates to make it easier to make changes to your labels and titles.

## 5. Can I save my graph as an image in C++?

Yes, you can save your graph as an image in C++ by using the getimage() and putimage() functions in the graphics.h library. These functions allow you to capture the graph as an image and then save it to a file. Keep in mind that the image will be saved in the same size and resolution as your graph, so it is important to adjust these settings accordingly.

• Programming and Computer Science
Replies
89
Views
4K
• Programming and Computer Science
Replies
30
Views
2K
• Programming and Computer Science
Replies
10
Views
1K
• Programming and Computer Science
Replies
2
Views
1K
• Programming and Computer Science
Replies
75
Views
4K
• Programming and Computer Science
Replies
4
Views
833
• Programming and Computer Science
Replies
36
Views
3K
• Engineering and Comp Sci Homework Help
Replies
2
Views
2K
• Programming and Computer Science
Replies
1
Views
3K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K