#include<iostream.h>
#include<iomanip.h>
using namespace std;

float number1, number2, number3;
void readThreeNumbers(number1, number2, number3);
void sortThreeNumbers(number1, number2, number3);
void displayNumbers(number1, number2, number3);

int main () 
{
readThreeNumbers(number1, number2, number3);
sortThreeNumbers(number1, number2, number3);
displayNumbers(number1, number2, number3);
}    
void readThreeNumbers(number1, number2, number3)
{
cout << "Please enter three floating-point numbers, space between them: ";
cin >> number1 >> number2 >> number3;
}
void sortThreeNumbers(number1, number2, number3)
{
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
if (number2 > number3)
{
temp = number2
number2 = number3
number3 = temp
}
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
}
void displayNumbers(number1, number2, number3)
{
 cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);                      
cout << "The average of " << number1 << "," << number2 << " and " << number3 << " is " << ;
system("pause");
}

i have this code that which inputs three number sort the three numbers in
ascending order then output the three numbers.

i'm getting this list of errors but i don't know how fix it.

In function `int main()':
`readThreeNumbers' cannot be used as a function
`sortThreeNumbers' cannot be used as a function
`displayNumbers' cannot be used as a function

At global scope:
`readThreeNumbers' declared void
`int readThreeNumbers'
`int readThreeNumbers' previously declared here
expected `,' or `;' before '{' token
`sortThreeNumbers' declared void
redefinition of `int sortThreeNumbers'
`int sortThreeNumbers' previously declared here
expected `,' or `;' before '{' token
`displayNumbers' declared void
redefinition of `int displayNumbers'
`int displayNumbers' previously declared here
expected `,' or `;' before '{' token

Lines 6-8 are the prototypes and they need the types of the variables e.g., void readThreeNumbers(float number1, float number2, float number3); (in the prototype the names number1,number2, and number3 are optional, not the types).

Since you are passing the float variables into your functions anyway, and because global variables are a bad habit to get into, you should move line 5 inside of main().

Also, you should remove the .h from your header files, the ones with the .h are prestandard.

Also, there is no reason to use global variables here. Define number1,2,3 in main and then pass them by reference to the functions.

Dave

ok this is it now

#include<iostream>
#include<iomanip>
using namespace std;


void readThreeNumbers(float number1,float number2,float number3);
void sortThreeNumbers(float number1,float number2,float number3);
void displayNumbers(float number1,float number2,float number3);

int main () 
{
float number1, number2, number3;
readThreeNumbers(number1, number2, number3)
{
cout << "Please enter three floating-point numbers, space between them: ";
cin >> number1 >> number2 >> number3;
}
sortThreeNumbers(number1, number2, number3)
{
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
if (number2 > number3)
{
temp = number2
number2 = number3
number3 = temp
}
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
}
void displayNumbers(number1, number2, number3)
{
 cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);                      
cout << "The average of " << number1 << "," << number2 << " and " << number3 << " is " << ;
system("pause");
}

but now im getting a lot of syntax errors
line:
14. expected `;' before '{' token
19. expected `;' before '{' token
40. expected `;' before '{' token
44. expected `}' at end of input

Looks like you have some extra braces scattered throughout. Also, to pass by reference you have to do:

void readThreeNumbers(float &number1,float &number2,float &number3);

Dave

You seriously need to indent your code, then mistakes with extra or missing braces couldn't happen.

The issue is not that there are extra/missing braces. The issue is that you are trying to define your *ThreeNumbers functions inside of main(). You can't do that.

You need your prototypes before main() and definitions after main() like you had in your first version. You simply need to correct the syntax and variable usage.

Indenting FTW. It's be much easier to spot what was wrong here if you indented each level of scope. The problem, as Fbody says, is that you're trying to define your functions inside of main, which is not allowed.

i've fixed it now.

#include <iostream.h>

void readThreeNumbers(int &, int &, int &);
void sortThreeNumbers(int &, int &, int &);
void displayNumbers(int, int, int);

int  main()
{
int number1, number2, number3;
readThreeNumbers(number1, number2, number3);
sortThreeNumbers(number1, number2, number3);
displayNumbers(number1, number2, number3);
}
void readThreeNumbers(int &number1, int &number2, int &number3)
{
cout << "Enter three numbers, with a space between them: ";
cin >> number1 >> number2 >> number3;
}
void sortThreeNumbers(int &number1, int &number2, int &number3)
{
int temp; 
if (number1 > number2)
{
temp = number1;
number1 = number2;
number2 = temp;
}
if (number2 > number3)
{
temp = number2;
number2 = number3;
number3 = temp;
}
if (number1 > number2)
{
temp = number1;
number1 = number2;
number2 = temp;
}
}
void displayNumbers(int number1, int number2, int number3)
{
cout << "\nThe numbers sorted in ascending order are\n"
<< number1 << endl
<< number2 << endl
<< number3 << endl;
system ("pause");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.