₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,453 members, 8,511,993 topics. Date: Monday, 02 November 2026 at 04:05 PM

Toggle theme

Please What Is The Logic Behind This Program (C++), I'm Bored. - Education - Nairaland

Nairaland Forum › Nairaland General › Education › Please What Is The Logic Behind This Program (C++), I'm Bored. (722 Views)

1 Reply (Go Down)

Please What Is The Logic Behind This Program (C++), I'm Bored. by jpawjpaw(op): 2:03pm On Jun 24, 2020
I'm a beginner in C++, we were just starting the course (CSC 201) before oga Corona sent us back home. Incase you have knowledge in C++, I need your help please.
Is this a logic error, or the C++ was designed that way;
sin 30 = 0.5 normally, but here in my program, I'm getting -0.98803(negative number), same goes with sin 60.
Here is the program below, incase u have an idea, please help a brother.

#include <iostream>
#include <cmath>
using namespace std;
int main ( )
{
double x = 30.0;
double y = 2.0;
cout << sin (x) <<endl;
cout << x/y <<endl;
// I want the program to print 0.5 and 15.
// but I'm getting something else.
return 0;
}

so please what could be the problem?
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by Davechuks360(m): 7:26pm On Jun 24, 2020
Sin and Cos functions take the angle parameter in radian. You should convert the angle to radian first before passing into the sin/cos function.

I don't really know c++, but in Java, you'll use Math.toRadian(angle in degree).
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by clockwisereport: 8:33pm On Jun 24, 2020
.
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by Scout60(m): 10:35pm On Jun 24, 2020
jpawjpaw:
I'm a beginner in C++, we were just starting the course (CSC 201) before oga Corona sent us back home. Incase you have knowledge in C++, I need your help please.
Is this a logic error, or the C++ was designed that way;
sin 30 = 0.5 normally, but here in my program, I'm getting -0.98803(negative number), same goes with sin 60.
Here is the program below, incase u have an idea, please help a brother.

#include <iostream>
#include <cmath>
using namespace std;
int main ( )
{
double x = 30.0;
double y = 2.0;
cout << sin (x) <<endl;
cout << x/y <<endl;
// I want the program to print 0.5 and 15.
// but I'm getting something else.
return 0;
}

so please what could be the problem?
I guess you are a futo student?
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by jpawjpaw(op): 10:43pm On Jun 24, 2020
Scout60:
I guess you are a futo student?
Nop, why did u say so?
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by jpawjpaw(op): 11:22pm On Jun 24, 2020
Davechuks360:
Sin and Cos functions take the angle parameter in radian. You should convert the angle to radian first before passing into the sin/cos function.

I don't really know c++, but in Java, you'll use Math.toRadian(angle in degree).
okay sir, thank u.
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by jpawjpaw(op): 11:24pm On Jun 24, 2020
Scout60:
I guess you are a futo student?
#Mautech
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by Scout60(m): 8:11am On Jun 25, 2020
jpawjpaw:
Nop, why did u say so?
Because of the course code.... are you learning c++ to know or just pass your exams?
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by jpawjpaw(op): 9:35am On Jun 25, 2020
Scout60:
Because of the course code....
are you learning c++ to know or just pass your exams?
Oooh, ok........
I'm learning to know oo, not just pass my exams;
learning to just pass exams is not the way out. I have done that in my 100L, and then it was Java, I crammed to pass, and now I've forgot almost everything in Java; so I can't afford to repeat that in c++.
I want to become a guru in it.
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by Scout60(m): 11:01am On Jun 25, 2020
jpawjpaw:
Oooh, ok........
I'm learning to know oo, not just pass my exams;
learning to just pass exams is not the way out. I have done that in my 100L, and then it was Java, I crammed to pass, and now I've forgot almost everything in Java; so I can't afford to repeat that in c++.
I want to become a guru in it.
Java and c++ is always complex for beginners. If you want to become in c++ then find a personal tutor that will guide you but if you want to learn on your own, I suggest you start with python which is beginner- friendly. With python, u will understand how programming works and you will put the ideas towards learning c++
Re: Please What Is The Logic Behind This Program (C++), I'm Bored. by jpawjpaw(op): 11:28am On Jun 25, 2020
Scout60:
Java and c++ is always complex for beginners. If you want to become in c++ then find a personal tutor that will guide you but if you want to learn on your own, I suggest you start with python which is beginner- friendly. With python, u will understand how programming works and you will put the ideas towards learning c++
wow thanks for the idea, I really appreciate.

I will do as you said.
1 Reply

The Logic Of Writing • Logic Behind Best Placement Offers At T. A. Pai Management Institute? • I Need A Detailed Explanation To This Funny But Real Logic Question. • 2 • 3 • 4

What's The Decision That Changed Your Life? • The Richest State In Nigeria 2021 • Air Force Institute Of Technology (AFIT) School Fees Schedule For 2020/2021