Cin and Cout statements

Hi all,
it seems that every time that I try to run this code it come up with an error stating that the 'fulltotal' and 'fullinput' are not initialized and I am not sure why.
Any help would be great, thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <iostream>
#include <cmath>
using namespace std;

int main()
{
	double fullcases, fullservings, fullliters,fullinput, fullgallons, bottles, fullpallets;
	bottles = (.5 / 16) * 1960;
	fullservings = fullinput* 1920;
	fullliters = 1920 * fullinput;
	fullcases = fullinput / 80;
	fullgallons = fullliters * 0.264172;
	fullpallets = fullgallons * 8.345;


	cout << "Please enter the number of pallets of full-liter bottles needed:";
	cin >> fullinput;
	cout << "the number of full cases is" << fullinput * fullpallets << ".\n";
	
	
	return 0;
}
Last edited on
> fullcases = fullinput / 80;
is not an equation, is an assignment.
It says, take the value of `fullinput', divide by 80 and store that in `fullcases'

At the point of execution `fullinput' has garbage.
7
8
9
10
	double fullcases, fullservings, fullliters,fullinput, fulltotal, fullgallons, bottles, fullpallets;
	bottles = (.5 / 16) * 1960;
	fullservings = fulltotal * 1920; // what value does fulltotal have here?
	fullliters = 1920 * fullinput; // what value does fullinput have here 


In the tradition of the C language, in C++ there's no implicit initialization for built-in data types, such as the double's in your case.

So unless you explicitly initialize them, they will have garbage value.

1
2
3
double d = 90.0; // initialization (declaration and given value)

d = 85.5; // assignment 

Topic archived. No new replies allowed.