Last Project

#include <iostream>//required to perform C++ stream I/O
#include <iomanip>//required to manipulate C++ I/O Stream

using namespace std;//for accessing C++ Library Members
//function begins main program execution
int main ()

{
//define variables
float sum;//the total of three input numbers
float average;//the three input numbers divided by 3
float first_number;//the first number the user enters
float second_number;//the second number the user enters
float third_number;//the third number the user enters
float median;//the middle number when three numbers are arranged in order
float maximum;//the largest of the three input numbers
float minimum;//the smallest of the three input numbers




cout << "This program will determine the sum, average, median,\n maximum and minimum of three input numbers.";//Display program information to the user

cout << "\nPlease input the first number: ";//prompt user for input
cin >> first_number;//gets input from user

cout << "\nPlease input the second number: ";//prompt user for input
cin >> second_number;//gets input from user

cout << "\nPlease input the third number: " ; //prompt user for input
cin >> third_number; //gets input from user


cout << "\nThe three numbers entered are: " <<first_number <<second_number <<third_number <<endl;//displays input to user

sum=(first_number+second_number+third_number); //calculates value of all 3 numbers that user input
cout << "\nThe sum is : " <<sum<<endl; //displays sum calculation result to user

average=(first_number+second_number+third_number)/3; //calculates average of three numbers entered
cout << "\nThe average is: " <<average<<endl; //displays average calculation result to user


if (first_number >= second_number && first_number <=third_number) //evaluates the size of the number
cout << "\nThe median number is " <<median <<endl; //outputs median to user if logical conditions are met
else
if (second_number >= first_number && second_number <= third_number) //evaluates the size of the number
cout << "\nThe median number is " <<median <<endl; //outputs median to user if logical conditions are met
else
cout << "\nThe median is: " <<median <<endl; //displays median number to user


if (first_number > second_number && first_number >third_number) //evaluates the size of the number
cout << "\nThe maximum number is " <<maximum <<endl; //outputs evaluation to user if logical conditions are met
else
if (second_number > first_number && second_number > third_number) //evaluates the size of the number
cout << "\nThe maximum number is " <<maximum <<endl; //outputs evaluation to user if logical conditions are met
else
cout << "\nThe maximum number is " <<maximum <<endl; //outputs evaluation to user if logical conditions are met


if (first_number < second_number && first_number < third_number) //evaluates the size of the number
cout << "\nThe minimum number is " <<minimum <<endl; //outputs evaluation to user if logical conditions are met
else
if (second_number < first_number && second_number < third_number) //evaluates the size of the number
cout << "\nThe minimum number is " <<minimum <<endl; //outputs evaluation to user if logical conditions are met
else
cout << "\nThe minimum number is " <<minimum <<endl; //outputs evaluation to user if logical conditions are met


return 0;

1>e:\intro2programming\project3\p3ktg\p3ktg\p3ktg.cpp(52) : warning C4700: uninitialized local variable 'median' used
1>e:\intro2programming\project3\p3ktg\p3ktg\p3ktg.cpp(61) : warning C4700: uninitialized local variable 'maximum' used
1>e:\intro2programming\project3\p3ktg\p3ktg\p3ktg.cpp(70) : warning C4700: uninitialized local variable 'minimum' used

If I can get the teacher to accept this error free, I might just make a B
you dont need float median-float maximum-float minimum

i fixed for you hope it helps

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>//required to perform C++ stream I/O
#include <iomanip>//required to manipulate C++ I/O Stream

using namespace std;//for accessing C++ Library Members
//function begins main program execution
int main ()

{
//define variables
float sum;
float average;
float first_number; // dont need
float second_number; //dont need
float third_number; // dont need

cout << "This program will determine the sum, average, median,\n maximum and minimum of three input numbers.";

cout << "\nPlease input the first number: ";
cin >> first_number;

cout << "\nPlease input the second number: ";
cin >> second_number;

cout << "\nPlease input the third number: " ;
cin >> third_number; 


cout << "\nThe three numbers entered are: " <<first_number <<second_number <<third_number <<endl;

sum=(first_number+second_number+third_number); 
cout << "\nThe sum is : " <<sum<<endl; 

average=(first_number+second_number+third_number)/3; 
cout << "\nThe average is: " <<average<<endl;


if (first_number >= second_number && first_number <=third_number) 
cout << "\nThe median number is " << first_number << endl; 
else 
if (second_number >= first_number && second_number <= third_number)
cout << "\nThe median number is " << second_number <<endl; 
else
cout << "\nThe median is: " <<third_number <<endl; 


if (first_number > second_number && first_number >third_number) //evaluates the size of the number
cout << "\nThe maximum number is " <<first_number <<endl; //outputs evaluation to user if logical conditions are met
else
if (second_number > first_number && second_number > third_number) //evaluates the size of the number
cout << "\nThe maximum number is " <<second_number <<endl; //outputs evaluation to user if logical conditions are met
else 
cout << "\nThe maximum number is " <<third_number <<endl; //outputs evaluation to user if logical conditions are met


if (first_number < second_number && first_number < third_number) //evaluates the size of the number
cout << "\nThe minimum number is " <<first_number <<endl; //outputs evaluation to user if logical conditions are met
else
if (second_number < first_number && second_number < third_number) //evaluates the size of the number
cout << "\nThe minimum number is " <<second_number <<endl; //outputs evaluation to user if logical conditions are met
else 
cout << "\nThe minimum number is " <<third_number <<endl; //outputs evaluation to user if logical conditions are met

system("pause");
return 0;}

i tryied to remove comments but took to long...
Last edited on
Uninitialized variable means that you are using a variable that has no set value. Initialize all of your variables to zero or some other value before you use them. (Unless there is input that initializes them)

Also that code is error free, those are just warnings.
Topic archived. No new replies allowed.