Need help with my CODE!

Alright, I have a project due in a couple of days, and i'm stuck, but I also need some suggestion. I'm doing a Sine/Cosine Law program, and I must have 2 functions(1 of them need must be a recursive function), a string, and arrays included in my program. The thing is, I have no clue how to incorporate strings and arrays into my program. I have include 2 functions, but neither of them are recursive as I know so far. Also, it isn't compiling properly. Can you guys give suggestions and figure out the problem with my program?

Here is my program so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string> 
#include <math.h>  
using namespace std;
void sineLaw(void);
void cosLaw(void);
int main(){
char select;
double a,b,A,B;
cout<<"What would you like to figure out?"<<endl;
cout<<"a)SineLaw"<<endl<<"b)CosineLaw"<<endl;
cout<<"Select either a or b"<<endl;
cin>>select;

if(select=='a'){
cout<<"Enter the side length of 'a' & 'b'"<<endl;
cout<<"Enter the size of angle 'A' & 'B' "<<endl;
cout<<"a:";
cin>>a;
cout<<endl;
cout<<"b:";
cin>>b;
cout<<endl;
cout<<"A:";
cin>>A;
cout<<endl;
cout<<"B:";
cin>>B;
cout<<endl;
sineLaw();
}

else if(select=='b'){

}

else
cout<<"Your input is invalid. Valid options are a or b"<<endl;
return 0;
}


void sineLaw(void){
double a,b,c,A,B,C;
double PI=3.14;
C=180-(A+B);  
c = (A*(sin((C*PI/180))))/((sin(A*PI/180)));
cout<<"Angle C:"<<C;
cout<<"Length of c:"<<c;
}

Last edited on
use code tags please, it makes the program easier to read.

I put the program in my compiler and commented it, tell me if any of this helps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
void sineLaw(void);
void cosLaw(void); //change parameters(explained in function below)
int main(){
    char select;
    double a,b,A,B; //might want to turn this into an array for your assignment, maybe labeled "Triangle[4]"
    //Triangle[0] -- a
    //Triangle[1] -- b
    //Triangle[2] -- A
    //triangle[3] -- B
    cout<<"What would you like to figure out?"<<endl;
    cout<<"a)SineLaw"<<endl<<"b)CosineLaw"<<endl;
    cout<<"Select either a or b"<<endl;
    cin>>select;

    if(select=='a'){
        cout<<"Enter the side length of 'a' & 'b'"<<endl;
        cout<<"Enter the size of angle 'A' & 'B' "<<endl;
        cout<<"a:";
        cin>>a;
        cout<<endl;
        cout<<"b:";
        cin>>b;
        cout<<endl;
        cout<<"A:";
        cin>>A;
        cout<<endl;
        cout<<"B:";
        cin>>B;
        cout<<endl;
        sineLaw(//Triangle);
    }

    else if(select=='b'){

    }

    else
    cout<<"Your input is invalid. Valid options are a or b"<<endl;
    return 0;
}


void sineLaw(void){
    double a,b,c,A,B,C; //you create 6 variables here, all of these values are initially set to zero
    //you need to pass the values from main over to this function, the best option would be to pass 
    //an array holding these values into the function using parameters(void sineLaw(double Ar[]))
    double PI=3.14;
    C=180-(A+B);
    c = (A*(sin((C*PI/180))))/((sin(A*PI/180))); 
    cout<<"Angle C:"<<C;
    cout<<"Length of c:"<<c;
}
Last edited on
First off, use code tags. If I wasn't bored at work, I wouldn't have even read this.

Second, do you understand how to use functions? None of the values you get from the user, are actually used.
Last edited on
closed account (ypfz3TCk)
Your functions are not correctly defined.
You have indicated void for return and void for arguments passed by the user. I would expect that you want the values input by the user to be processed by the function. That means the function must be written so it accepts input and returns a value.
hth
@ Need4Sleep
Ahh that must be why it wasn't compiling properly. Thanks. Oh, do you mind explaining the how to turn a,b,A,B into arrays.
@ResidentBiscuit
I'm new to these forums, so I have no idea how to use code tags.
A note to others.

Please don't solve his homework for him.

Tradechat: he tells you how in his comment. If you don't understand you should consult your textbook looking under pass by value arguements to functions. Any text on the screen can be made a string.

I know your trying to get this done but your questions seem like you just want us to do the work for you. These questions are explained thoroughly in any textbook OR online tutorial. If you read them and then don't understand the concepts I would suggest coming back and asking for a more in depth explination.
@Senjai
dont be so harsh, if you read his first post:
Can you guys give suggestions and figure out the problem with my program?
he doesn't ask for any of it to be done for him, he is just asking for help. Please don't go around spitting on the newer users, it discourages them from posting anything.

With the topic:
i recommended scratching the whole double values and instead creating an array to hold the data. Like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
std::string Gerald,John,Jacob,Johnson; //pretend the names correspond to the data they hold(Gerald = "Gerald")
//passing these as arguments can be a pain:
void NameSorter(int i, int i2, int i3... etc... etc..)
//int main:
//calling function with parameters
NameSorter(Gerald,John,Jacob,Johnson....); //can get messy.
//-------------------------------------------------------------
std::string Names[4] = {//Data}
//passing an array through a function is neat and organized
void NameSorter(std::string Ar[]);
//int main:
//calling function with parameters
NameSorter(Names);

//Note** Arrays are passed by reference through functions by default(modifying the contents of the array inside a function will do the same
//for the array outside of the function) 


Make sense?
@Need4Sleep
Somewhat makes sense, but I what I don't understand is how I would put these steps into my program.

EDIT: Also, it seems it gives an error when information from NameSorter goes to NameSorter("the 4 strings")
Error is: No suitable conversation function from "std::string" to "int exist. Can you elaborate on that? Thanks
Last edited on
Here's a couple things you need look into:

1
2
3
4
5
6
7
8
9
10
11
12
void sineLaw(void)    // Something's wrong with the contents of (     )
{
double a, b, c, A, B, C;   // You've declared some new variables
double PI = 3.14;

C = 180 - ( A + B );        //  Here's a hint, if I told you to write down the value of A and B on a piece of paper, what would you write down?
c = ( A * ( sin ( ( C * PI / 180 ) ) ) ) / ( ( sin ( A * PI / 180 ) ) );   // Probably a little too much in terms of spacing, but if you want others
// to read your code, this is along the lines of what you want to do

cout << "Angle C:" << C << endl;
cout << "Length of c:"<< c << endl;
}


Edit: Oopsie, pulled a stupid.
C = 180 - A - B;

Last edited on
C = 180 - ( A + B ); // This is the same as C = 180 - A + B; The brackets () aren't necessary.

Not true.
1
2
3
4
5
c  = 180 - ( A + B );

//is the same as 

C = 180 - A - B; 
Last edited on
Topic archived. No new replies allowed.