Hi,

I am trying to set up a program to allow the user to enter an odd number between 3 and 31. The program will then divide 360 between 1 and the user input-1. For example say the user enters 7, the program should divide 360 to each value 1, 2, 3, 4, 5, 6. I could really do with the program to divide by 0 as well so that the total values the 360 would divide into would be 7. So now the program should have the values 360/1, 360/2, 360/3, 360/4, 360/5 etc. These values are degrees which i need to take the sin of.

To try and tackle this problem i have used a counter to count from 1 upto the user input -1.
for ( i=0; i=uservalue-1; i++) Stored these values into an array, then divided 360 into each element by saying a = i and then a = 360 / a. Next the sin calculation is used by saying a = sin(a). Now apparantly sin only works with radians, everytime i convert my degrees into radians and do the sin of them i get no minus values!

How else can i calculate the degrees from the user input. Ive spent weeks trying to sort this out, really beginning to hate c++!!

Well in degree terms
360 / 1 = 360, and the sin of this is 0
360 / 2 = 180, and the sin of this is 0 as well.
360 / n is always going to be between 0 and 180, and sin over this range is always positive.

At what point were you expecting a negative result?

Yes, you always need to convert to radians.
Perhaps show how you tried to do it, rather than describe it.

Did you perhaps try it using an int variable, rather than a double ?

Hi,

I have had another idea to approuch this. First of all im going to enter the number (odd between 3 and 31) then divide 360 by that number to obtain the first degree.

double a[30];
double c = rate - 1;     //value of rate = user input at beginning
double b = (360 / c);  //360 / 6 (if user input was 7)
int i;

for ( i=0; i<=rate; i++ ){    
    a[i] = i; }


cout << a[i] << endl;

Using a counter i am going to count 0 upto the user input, store values into the array.
Then muliply the array elements by b.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

By the way, you should have posted this in the C forum. There is nothing specific to C++ in this thread.

The reason i posted this again was because the last post was confusing and long winded. I figured writting it out again would help me and the readers. Thanks

By the way, you should have posted this in the C forum. There is nothing specific to C++ in this thread.

There's nothing specific to C either. Other than he's writing a C++ program.

> you should have posted this in the C forum. There is nothing specific to C++ in this thread.
do you really mean

namespace { int foobar( int i ) { return ++i ; } }

is c++, but if you place the same function in the global namespace, it suddenly stops being c++?

do you really mean
(Toggle Plain Text)
namespace { int foobar( int i ) { return ++i ; } }namespace { int foobar( int i ) { return ++i ; } }
is c++, but if you place the same function in the global namespace, it suddenly stops being c++?

Okay, agreed. It is because of C++ that we know the concept of namespaces. But if we see the code posted, there is no need of specifying a global namespace. What you are saying is that using the concepts because they are known. What I'm saying is no advanced concepts are needed if the aim is just to solve this problem. No offense is meant :).

i think you misunderstood what i meant. let me clarify. there are constructs which are clearly C++, there are others which are clearly C (and not C++). and there are many which could be either. i suggest that in these cases we should assume that the person who posed the question knows best what language he/she is programming in. for example, if someone has issues with dynamically resized arrays, suggesting the use of a std::vector instead is possible in C++, not in C.
i see now that WaltP had already pointed this out earlier; i must have missed his post while replying.

This article has been dead for over six months. Start a new discussion instead.