Thread: decimals to int?

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    4

    decimals to int?

    my objective is to write a program that
    a. prompts the user to input 5 decimal numbers
    b.. prints the 5 decimal numbers
    c. converts each decimal number to the nearest integer
    d. adds the 5 integers
    e. Prints the sum and the average of the 5 integers

    this is what i have so far
    Code:
    // main
    #include <iostream>
    using namespace std;
    
    void extern input (double, double, double, double, double);
    
    void extern calculate (double num1, double num2, double num3, double num4, double num5);
    
    void extern output (double num1, double num2, double num3, double num4, double num5);
    
    int main()
    
    {
        // Declaration (data)
        double num1, num2, num3, num4, num5;
        
        
        // Logic (executable)
        
        input (num1, num2, num3, num4, num5);
        
        calculate ( num1, num2, num3, num4, num5);  
        
        output (num1, num2, num3, num4, num5);
                   
        system ("Pause");
        return 0;  
        
    }
    Code:
    // input
    #include <iostream>
    using namespace std;
    
    void input (/* out */ double num1, double num2, double num3, double num4, double num5)
    {
        cout << "Please enter a decimal: ";
    	cin >> num1;
    	cout << endl;
    	cout << "Please enter a decimal: ";
    	cin >> num2;
    	cout << endl;
    	cout << "Please enter a decimal: ";
    	cin >> num3;
    	cout << endl;
    	cout << "Please enter a decimal: ";
    	cin >> num4;
    	cout << endl;
    	cout << "Please enter a decimal: ";
    	cin >> num5;
        cout << endl;
        
    }
    Code:
    // calculate
    
       
       void calculate ( /* in */ double num1, double num2, double num3, double num4, double num5)
    {        
          // local declarations
    
        total, average;
        
     // executable
           
           total = (num1 + num2 + num3 + num4 + num5);
           average = (5 / total);
                
    }
    Code:
    // output
    
    #include <iostream>
    using namespace std;
    
    void output ( /* in */ int num1, int num2, int num3, int num4, int num5)
    
    {
    
         cout << " The Original Numbers Were: " << num1 << num2 << num3 << num4 << num5 << endl;
         
         cout << " The total is: " << total << endl;
         
         cout << " The Average is: " << average << endl;
         
         
    
    }
    any tips would be great im just really stuck and dont know really what to do

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Does the program compile without errors and warnings?

    If not what are the error/warning messages, post the entire message.

    If you have no errors what is wrong with your program?

    What is your input?

    What is your output?

    What did you expect your output to be?

    Jim

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    this is the error i get when compileing
    Circular output <- output.o dependency dropped.
    Circular Input <- Input.o dependency dropped.
    Circular Calculate <- Calculate.o dependency dropped.
    F:\C++\project\dec to int\Makefile.win [Build Error] [Project1.exe] Error 1
    my input is the second piece of code and my output is the last

    and my objective is to write a program that
    a. prompts the user to input 5 decimal numbers
    b.. prints the 5 decimal numbers
    c. converts each decimal number to the nearest integer
    d. adds the 5 integers
    e. Prints the sum and the average of the 5 integers

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    What compiler are you using?

    Are the functions all in one file or in multiple files?

    Try to remove the extern from your function prototypes.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    dev C++

    Yes they are in diffent files

    and what will that do?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Quote Originally Posted by nixxonn View Post
    dev C++

    Yes they are in diffent files

    and what will that do?
    Possibly fix your errors

    Circular output <- output.o dependency dropped.
    Circular Input <- Input.o dependency dropped.
    Circular Calculate <- Calculate.o dependency dropped.
    F:\C++\project\dec to int\Makefile.win [Build Error] [Project1.exe] Error 1
    Jim

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    didnt work, same error

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    void input (/* out */ double num1, double num2, double num3, double num4, double num5)
    The comment "out" does nothing to make the variables output in C!
    I suggest learning how pointers are used to return values in C. Or pass by reference in C++
    I assume the same is true for C++.

    Tim S.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I've seen other ways people get a simple average calculation wrong, but this is new:
    Code:
    average = (5 / total);
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM