need assistance please

i have a question why doesnt this work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <stdio.h>
#include "windows.h"
#include <fstream>

using namespace std;
double largest(int a, int b,int c);
int a=2;
int b=3;
int c=10;
int main()
{
	
	cout<< "numbers to be checked are 2,3, and 10 "<< endl;
	largest(2,3,10);
	cout<< "the largest number is: "<< endl;
	system("pause");
	return 0;
}

double largest(int a, int b,int c)
{

if (a>b&&a>c)
{
	cout << a;
	return a;
}
else if (b>a&&b>c)
{
	cout<< b;
	return b;
}
else
{
	cout<< c;
	return c;
}


}
Last edited on
Hi, at first glance I notice your function largest is returning a double but is not being used.

At line 19 in your program you are returning a double but not doing anything with it, i assume you expect the output to be "the largest number is: largestnumber"

You could add the call to largest into the same line as line 20 and make it look something like
 
cout << "the largest number is: " << largest(2,3,10) << endl;


alternatively you could change line number 19 to store the largest value in a double and then use that in your statement on line 20. This can be accomplished like so

1
2
double largest_value = largest(2,3,10); // line 19
cout << "the largset number is: " << largest_value << endl; // line 20 
thanks a lot i had this on my final as a question and i didnt turn it in because of that ...... i guess every one makes mistakes. thanks anyways
Topic archived. No new replies allowed.