Yes javascript can accomplish this quite well.
Yes javascript can accomplish this quite well.
Close. But still it will give wrong output. I will drop a hint.
for(int i=0;i<=5;i++)
{
//something goes in here...
}
cout>>i;
guess what is the output of i ?
And similarly whats the value of ctr1 when it comes out of the 1st loop.
Is that the value you want ctr2 to be initialized to ? ;)
for (ctr2=0;ctr2>=0;ctr2--)
Now what have you done here ? You are saying to the loop ...
Initialize ctrl2 to 0, decrement it by 1 every time, run the loop till its greater than or equal to 0 ........ ??? It will run the loop exactly 1ce!!
As everytime the the 2nd time loop is about to run it fails the condition ctrl2 >=0.
You need to think and code how to display an array in reverse.
Hint: wrong intitialization in this 2nd for loop.
for (ctr2=0;num>=0;ctr2--)
{
cout<<bin[ctr2];
}
fault in your for loop. its telling :
initialize ctrl2 to 0, decrement it every time by 1, run the loop till num>=0 .
So always num >=0 , as its unchanging in the loop. hence it runs for infinite.
Thats wonderful!! See how pleasurable it is to find out a solution on your own!! :D
Ok , now for another self discovery. Check the difference between long int and long double.
Good thing you proposed a challenging project. You will learn much more this way and your knowledge base will increase considerably. Don't be bothered about "biting off more than you can chew" ... u will choke, and then you will swallow , with pain, and you will be the wiser for it.
There is a vast ocean of resource available online to teach you all about C++ graphics and multimedia. just google well and all shall be disclosed. For starters practice functions well and get to know arrays well. and then you should be 50% there. My Best wishes!
A Wonderful book on C++ is Bruce Eckel's Thinking in C++ , its free for download and will teach u all u need.
What you have done is :
num *= num;
num--;which will do the following :
1. if suppose you entered 3.
num *= num will giv num = 3*3 = 9
then num-- i.e, 2
then it will proceed like:
9*2
Wrong. It will never be 9 * 2 , it will be 8 * 8 , as num -- takes it to 8 and then in the next while loop its num = 8 * 8 again.
its always num * num in the code , hence a squaring will take place. 9 * 2 doesn't come into the picture.
Thanks for teaching me why i got always an infinity as an output.... Let me see... all i have to do is just subtract one from the number you inputed.... and not the solution.... but what id i swap the num-- to --num what will that do??
My pleasure. Ok , yes you will have to substract 1 from the number you input. But not before the multiplication. Note how it works :-
if Num = 5 , you are looking for a product of
5 x 4 x 3 x 2 x 1 right ? So first the product then the decrement.
changing num-- to -- num will not help.
Lets try to see how this works :-
5! = 5 x 4 x 3 x 2 x 1
Which is 1 …
Ok lets do a dry run to see where you went wrong in the program.
Say num = 5
while num >= 1 ( 5 >=1 , hence true )
num = num * num , num becmes 25.
num = num -1 , num becomes 24
again while num > = 1 ( 24 > =1 , hence true )
num = num * num , num becmes 24 squared = 576
num = num - 1 , num = 575 now
and so now , so basically your variable num keeps increasing and the condition while num >= 1 is always true , and thus ur program takes num to infinity or maximum 16bit integer value.
I guess u are looking for something like 5! = 120 right ?
thats 5 x 4 x 3 x 2 x 1 . Hint : thats 5 multiplication , with each number 1 less. try some more, then we are here.
Any ways, what u desire is the circumference of the incircle ? Right ?
Largest circle that can be drawn inside a triangle is called an Incircle.
refer to http://www.mathopenref.com/triangleincircle.html
Not circumference of a triangle.
"Triangle with Rounded Corners" ? I do not get it.
I think what he meant was the perimeter of the Triangle.
There is no such technical term as Circumference of a Triangle. There is however the Circumference of a Circle.
With all due respect Ancient Dragon, I think you should get your facts checked before berating someone, what with your stature here. It doesn't look good.
However if someone means the Perimeter of a Triangle , calling it the circumference would be incorrect.
Thanks WaltP ...
system("PAUSE") <--- was a gr8 tip.
Circumference of a Triangle ? WTF !!!
Now ... why your program didnot Run.
using namespace std;
should be Global in scope . Meaning outside block of any function. If you do not define the namespace globally, u will have to use std::cin , std::cout inside every function.
area = sqrt(s(s-a)(s-b)(s-c));
1st , s*(s-a)*(s-b)*(s-c) is the correct way.
In CPP , product of two variables is signified by a*b , * is the multiplication operator.
2nd. sqrt is a library function found in the header file cmath,
double sqrt ( double x );
float sqrt ( float x );
long double sqrt ( long double x )
So s, a , b ,c must be defined as float.
consequently, in the main , side1,side2,side3 should also be defined as float.
or double as u choose.
Now lets come to the main.
cout << "The area of the triangle is " << area(side1, side2, side3) << endl;
area is a void function.. returns nothing. so printing it in the console is moot point.
Had area been a funtion having return type as float, then the above code may had some effect provided u had returned the area ffrom the function.
the modiefied code can look something like :
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
void area(float a, float b, float c )
{
float area;
float s;
s = ((a + b + c)/2);
if …