My code will compile, but it says I have not initialized my variables

As I said in the header this code will compile, yet it puts out erroneous results, and says the "wholesale" & "MarkUp" variables are not initialized. The output of the program remains the same no matter what input is entered. If you could help me to see what I am doing wrong I would greatly appreciate it.

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
// chap6proj.cpp : Defines the entry point for the console application.
//

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

double calculateRetail (double, double);

int main ()
{
double wholesale, MarkUp, Retail;
Retail = calculateRetail (wholesale, MarkUp);

cout << "This program will calculate the retail cost of any item.\n\n";
cout << "Enter the wholesale price of the item: ";
cin >> wholesale;
cout << "\n\nNow enter the mark up percentage as a whole number: ";
cin >> MarkUp;

if (wholesale >= 0 && MarkUp >= 0)
	{
	cout << setprecision (2) << fixed << showpoint;
	cout << "The retail price of the item is: " << Retail << endl << endl;
	}
else
cout << "The values entered may not be negative numbers.\n\n";

system ("PAUSE");
	return 0;
}

double calculateRetail (double Thing1, double Thing2)
{
return Thing1 * (Thing2 * .01) + Thing1;
}



Line 14.

Line 13 you declare variables with no assignment then in line 14 you try to send uninitialized variables to a function.

Move line 14 to line 21.
Last edited on
Also on line 9 when you declare your function prototype, you don't give names to the two doubles you are passing to the function.
Topic archived. No new replies allowed.