So we have to make a program to graph a Triangle and a Sine wave. The triangle bit is working fine, but the sine waves always comes out like this:
*
*
*
*
*
*
*
Instead of being properly curved. I double checked the math, so I know it is right, there is just some bug that is keeping the *'s from moving out on the X axis.
elseif (choice == 2)
{
{
void placePoint (int t ); //declaration, does nothing
if (t < 180); //semicolon, does nothing
for (int t=0; t < 180; t=t+4) //why not "t += 4"?
{
double ans;
double ans2;
int final;
//why separate the above and the below?
ans = t * 3.14 / 180; //looks ambiguous - use parens?
ans2 = sin(ans);
final = (int)(80.0 * ans2);
if (x < final); //semicolon, does nothing
{
x = x+1; //why not "++x;"?
cout << " ";
}
cout << "*" << endl;
}
}
return 0;
}
}
Semicolons are deviously hidden and not very obvious, but they are in plain sight. Look for semicolons that should not be there, such as the ones I pointed out in my post...
Yeah, I trimmed out some of the fat, as well as those two and got it...well I don't wanna say half working, but now I am even more confused on what happened.
The thing is, it is supposed to be roughly 45 lines, out to a potential of 80 spaces. I got it to give me the numbers it was using and I got:
0, 5, 11, 16, 22 etc etc etc, up to just shy of 80, where it then turned around and went back towards zero. So it is behaving like a Sine wave should mathematically, but I still am lost as to why it starts to shift at the start, and then sort of dies.
If you do ans2 = 1 + sin(ans); it should display the entire wave.
It does not. All it does is increase the numerical output and keep the same style as before. A bump at the start, and then it falls flat.
Also, I do not understand how the Sine could possibly be negative. The function only continues while t < 180. Stopping it at 180 degrees should keep all the numbers positive (or zero, in the case of t=0).
http://ideone.com/D9zId8
It takes advantage of the fill constructor of std::string, which takes a number and a character - the string is then initialized with the given number of the given character.