Problem with while loop

Hello!
So i'm working on a program assignment that requires me to figure out how many plants a florist sells in one day based on the temperature outside (I haven't completely finished). My problem is when I run the code it jumps past the while loop and ends the run. The compiler gave me no errors...so i'm guessing there's a logical error somewhere in my code. Can someone help and point out my error? Thanks in advance!

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

void fillArray(ifstream &infile, int myArray1[], int AVAILABLE_PLANTS)
{
//    fill array with input file and for loop
    infile.open("in.txt");

    if (infile.fail())    //if file does not open
    {
        cout << "input file could not be opened" << endl;
    }
//begin filling array with in.txt
        for (int i = 0; i < AVAILABLE_PLANTS; i++)
        {
            infile >> myArray1[i];
        }
//spits out array
/*            for (int i = 0; i < AVAILABLE_PLANTS; i++)
            {
                cout << myArray1[i]
                     << endl;
            }
*/
    infile.close(); //    close file
};

//create function that finds the approx. sold plants
int approxPlantsSold(int tempOutside, double &plantsSold, double &plantsLeft )
{
    int result;
    if (tempOutside < 40)
    {
//       calculate how many plants sold
        plantsSold = plantsLeft * .10;
        result = plantsLeft - round(plantsSold);
    }
    return result;
};

int main() {

//  declare arrays
int AVAILABLE_PLANTS = 8, OUTDOOR_TEMP = 5;
int myArray1[AVAILABLE_PLANTS];
//int myArray2[OUTDOOR_TEMP];
double plantsLeft = 100;
double plantsSold;

    ifstream infile;
    fillArray(infile, myArray1, AVAILABLE_PLANTS);

    int tempOutside;    //variable user inputs

    while(tempOutside != 0)
    {
        cout << "Our plant store is now open for business.\n"
             << "It is the first day and we have " << plantsLeft << " plants available\n"
             << "On the first day of opening, what is the outdoor temperature?\n"
             << "(Press 0 to end game)";
//    user enters first outdoor temperature
        cin >> tempOutside;

        cout << "With the temperature being " << tempOutside << endl
             << plantsSold << " plants were sold.\n"
             << "The number of plants remaining are: ";

//        call fxn that calculates amount of plants sold
        cout << approxPlantsSold(tempOutside, plantsSold, plantsLeft);


    }



    return 0;
}

You need to initialize tempOutside to a non-zero value. If you don't initialize it it could have any value, including zero, which would cause your while loop to never execute.
Topic archived. No new replies allowed.