Thread: Returning a float?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    3

    Question Returning a float?

    I am making a calculator for 8th grade geometry class. We are learning about trigonometric ratios. My problem is, I got the whole program written, and then I realized that my sines and cosines should be getting decimals. I realize the problem is because I'm using the wrong variable type. I checked it, and I'm using floats. I think the problem is my funtion is returning ints. Criticism welcome as long as it has to do with my problem. I'm new at this programming thing, just started 25 minutes ago in fact, so it's gonna be sloppy.


    Edit-----> Lol I just figured it out. I was using an int type function lol! I'm stupid!I'm stupid!I'm stupid!I'm stupid!



    Source Code ------->
    Code:
    // Trigonometric Ratios Helper.cpp : Defines the entry point for the console application.
    // By { A nanny Mouse! }
    
    #include "stdafx.h"
    #include <iostream> //Input Output
    
    using namespace std; //No idea but it looks cool =/
    
    int sine ( float b, float c );
    
    int main()
    {
      float Leglength1;
      float Leglength2;
      float hypotenuse;
      float sinea;
      float cosa;
      float tana;
      float tanb;
      cout<<"            {Blocked for forum use}'s  Amazing Trigonometric Ratio Helper!"<<"\n";
      cout<<"                            B" <<"\n";
      cout<<"                           /|" <<"\n";
      cout<<"                          / |" <<"\n";
      cout<<"                     Hyp /  |Leg2" <<"\n";
      cout<<"                        /   |" <<"\n";
      cout<<"                       A----C" <<"\n";
      cout<<"                        Leg1" <<"\n";
      cout<<"Please enter the length of a leg: ";
      cin>> Leglength1;
      cin.ignore();
      cout<<"Please enter the length of the other leg: ";
      cin>> Leglength2;
      cin.ignore();
      cout<<"Now the tricky part, enter the hypotenuse: ";
      cin>> hypotenuse;
      cin.ignore();
      sinea = sine(Leglength2, hypotenuse);
      cout<<"                            B" <<"\n";
      cout<<"                           /|" <<"\n";
      cout<<"                          / |" <<"\n";
      cout<<"                      " << hypotenuse << "  /  |"<< Leglength2 <<"\n";
      cout<<"                        /   |" <<"\n";
      cout<<"                       A----C" <<"\n";
      cout<<"                         "<< Leglength1 <<"    " << "\n";
      cout<<"Sin A: "<< sinea <<"\n";
      cin.get();
    }
    
    int sine ( float b, float c )
    {
      return b /= c;
    }
    Last edited by mandalord; 03-26-2007 at 03:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM