# Thread: decimals to int?

1. ## 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. 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. 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. 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. dev C++

Yes they are in diffent files

and what will that do?

6. Originally Posted by nixxonn
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. didnt work, same error

8. 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. I've seen other ways people get a simple average calculation wrong, but this is new:
Code:
`average = (5 / total);`

Popular pages Recent additions