Establishing a for loop in functions

Hi. I need to establish a for loop or at least a loop that will help me repeat a program 5 times while utilizing functions. My problem is any time I try to establish the loop in proximity to where it normally works, I get a variety of errors messages. Any help would be greatly appreciated.

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include <iostream>
using std::fixed;
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setprecision;

#include <stdlib.h>

void displaySummary(double, double, double, double);
void bedroomOption (const double &, const double);
double deckchoice (double, const double);
double cabinetchoice (double, const double);
double displayhouseOption (int);
double interiorchoice (double, const double, const double, const double, const double);
double discountFunction (double, double);
double finalCostFunction(double, double, double, double, const double, double, double, const double, double, double, const double); 
void displayWelcome ();
void displayNumberDone (int i);
void displayGoodbye ();
void houseOption (int);

void displayGoodbye (signed long long int);

int main ()
{

// 1: Declare Variables

   const double PERCENT_PROFIT= .25;
   const double STATE_TAX_RATE= .075;
   const double COST_PER_SQUARE_FT= 66.67;
   const double BEDROOM_SIZE= 360.0;
   const double WOODEN_CHOICE= 2000.0;
   const double DELUXE_CABINETS= 20000.0;
   const double WOOD_CHOICE= 10000.0;
   const double BRASS_FIX= 20000.0;
   const double CERAMIC_TILES= 25000.0;
   const double DELUXE_SAUNA= 30000.0;
   const double House_Square_Footage= 3000.0;

   double optionalFeatures= 0.0;
   double bedrooms= 0.0;
   double deck= 0.0;
   double cabinets= 0.0;
   double netHomeCost= 0.0;
   double basicHomeCost= 0.0;
   double taxes= 0.0;
   double profit= 0.0;
   double discount= 0.0;
   double totalHomeCost= 0.0;
   double interior= 0.0;
  
   int choice= 0.0;
   int i= 0.0;
  
   bool repeat = true;

// 2: Cost Determination Input

//display welcome
displayWelcome();

//House choice
displayhouseOption(choice);

//extra bedrooom choice
bedroomOption(House_Square_Footage, BEDROOM_SIZE);

//deck choice
deck = deckchoice(optionalFeatures, WOODEN_CHOICE);

//counter top choice
cabinets = cabinetchoice(optionalFeatures, DELUXE_CABINETS); 

//interior choice
interior = interiorchoice(optionalFeatures, WOOD_CHOICE, BRASS_FIX, CERAMIC_TILES, DELUXE_SAUNA);

//discount
discount = discountFunction(discount, optionalFeatures);

//Calculate
totalHomeCost = finalCostFunction(House_Square_Footage, netHomeCost, totalHomeCost, basicHomeCost, profit, COST_PER_SQUARE_FT, optionalFeatures, PERCENT_PROFIT, discount, taxes, STATE_TAX_RATE); 

//Display result     
displaySummary(basicHomeCost, optionalFeatures, discount, totalHomeCost);

//Display end
displayNumberDone(i);

//Display goodbye
displayGoodbye();
     
return 0;

}//end of the main function

//display welcome

void displayWelcome()

{
cout<<"Welcome to our program. This will help you determine the cost of your house"<<endl;
}

//display additions

//for loop function
for ( int i=1; i<=5; i++ )
void houseOption(int choice)
{
   {
   int choice= 0;
   cout << "For a standard house, please input 1. For a house with optional features, please input 2.\n";
   cin >> choice;
  
    if( choice !=1 && choice !=2 )
    {
        cout<<"Incorrect input detected \n";
        exit (1); //This stops the program
    }else if (choice ==2)
    { //custom made house
   
}

double bedroomOption(double & House_Square_Footage, const double BEDROOM_SIZE)
{
   int bedrooms =0;

   cout<<"If you would like extra bedrooms, please input 1 or 2 based on how many you would like.\n";
   cout<<"If you would not like any extra bedrooms, please input 0.\n";
   cin >> bedrooms

   //if user inputs unknown input
   if ( bedrooms != 0 && bedrooms != 1 && bedrooms != 2)
   {
      cout<<"Incorrect input detected\n";
      exit(2);
   } else {
   //if user inputs correct input
        House_Square_Footage += choice * BEDROOM_SIZE;
   }
    return House_Square_Footage;
}    
 
//2.2: Would you like a wooden deck?

double deckchoice(double optionalFeatures, const double WOODEN_CHOICE)

{
   int deck =0;

   cout<<"If you would like an extra deck worth $2000, please input 1.\n";
   cout<<"If you would not like the extra deck, please input 0.\n";
   cin >> deck;

  //if bad input
  if ( deck !=0 && deck !=1 )
  {
  cout <<"Incorrect input detected.\n";
  exit (3);
  } else {
  //if good input
  optionalFeatures += deck * WOODEN_DECK;
  }
   return optionalFeatures;
}
    
//2.3: Counter Tops choice

double cabinetoption(double optionalFeatures, const double DELXUE_CABINETS)
{
   int cabinetchoice=0;

   cout<<"If you would like a deluxe set of counter tops which cost $20,000, please input 1.\n";
   cout<<"If you would not like the deluxe counter top set, please input 0.\n";
   cin >> cabinetchoice;

   //if bad input
   if ( cabinetchoice !=0 && cabinetchoice !=1)
   {
   cout <<"Incorrect input detected.\n";
   exit (4);
   } else {
   //Correct input
   optionalFeatures += cabinets * DELUXE_CABINETS;
   }
   return optionalFeatures;
}
    
//2.4: House Interior

double interiorchoice(double optionalFeatures, const double WOOD_CHOICE, const double BRASS_FIX, const double CERAMIC_TILES, const double DELXUE_SAUNA)

{
      int floorChoice;
      floorchoice = 0.0;
      cout << "Now, please make your decision regarding the interior of the home.\n";
      cout << "For hard wood floors which cost $10,000, please insert 1.\n";
      cout << "For additional solid brass lighting fixtures which cost $20,000, please insert 2.\n";
      cout << "For additional specai plush carpeting, ceramic tiles and real wood panels which cost $25,000, please insert 3.\n";
      cout << "For gold kitchen and bath fixtures, a Jacuzzi, and a sauna which costs $30,000, please insert 4.\n";
      cin >> floorChoice;
      {
      if(floorchoice = 1){
      optionalFeatures += WOOD_CHOICE
      } else if{
      (floorchoice = 2)
      optionalFeatures += BRASS_FIX
      } else if{
      (floorchoice = 3){
      optionalFeatures += CERAMIC_TILES
      } else if{
      (floorchoice = 4){
      optionalFeatures += DELUXE_SAUNA
      } else {
      cout<<"Incorrect input detected";
      exit (5);
      }
return optionalFeatures;
}

//display discount

double discountFunction(double discount, double optionalFeatures)

{
  if ( optionalFeatures >= 30000.0 )
  {
       discount=(optionalFeatures * 0.10);
  }
  else if (optionalFeatures < 30000.0)
  {
          discount=0;
  }
  return discount;
}

//total cost final

double finalCostFunction(double House_Square_Footage, double netHomeCost, double basicHomeCost, double profit, const double COST_PER_SQUARE_FT, double optionalFeatures, double totalHomeCost, const double PERCENTAGEPROFIT, double discount, double taxes, const double STATE_TAX_RATE)

{
  basicHomeCost = House_Square_Footage * COST_PER_SQUARE_FT;
  profit = (basicHomeCost + optionalFeatures) * PERCENT_PROFIT;
  netHomeCost= basicHomeCost + optionalFeatures + profit - discount;
  taxes = netHomeCost * STATE_TAX_RATE;
  totalHomeCost = netHomeCost + taxes;
  return totalHomeCost;  
}

//display summary part 1

void displaySummary(double basicHomeCost, const double optionalFeatures, const double discount, const double totalHomeCost)

{
cout << "\nThe base cost is $"
     << fixed <<setprecision<basicHomeCost<<"\n"
     << "The total cost of optional features is $"<<optionalFeatures<<"\n"
     << "The discount is $"<<discount<<"\n"
     << "The total cost of your house is $"<< totalHomeCost <<endl;
}

//display summary part 2

void displayNumberDone(int i)

{
     cout <<"This is try number"<<i<<endl;
     cout << "If you would like to test another house, please input 1. If you would like to end, enter anything else." << endl;
     int customerinput;
     cin >> customerinput;
     repeat = customerinput == '1';
     if ( customerinput != 1)
     break;
    
}

//display goodbye

void displayGoodbye()

{
     cout <<Goodbye<<endl;
}

}
The problem you have is on line 111. You declared a statement outside of any function and since all you wanna do is repeat the functions 5 times. Just remove line 111 and put it on line 66, such that you have

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

displayWelcome();

//House choice
for( int i = 1; i <= 5; i++ ){
displayhouseOption(choice);

//extra bedrooom choice
bedroomOption(House_Square_Footage, BEDROOM_SIZE);

//deck choice
deck = deckchoice(optionalFeatures, WOODEN_CHOICE);

//counter top choice
cabinets = cabinetchoice(optionalFeatures, DELUXE_CABINETS); 

//interior choice
interior = interiorchoice(optionalFeatures, WOOD_CHOICE, BRASS_FIX, CERAMIC_TILES, DELUXE_SAUNA);

//discount
discount = discountFunction(discount, optionalFeatures);

//Calculate
totalHomeCost = finalCostFunction(House_Square_Footage, netHomeCost, totalHomeCost, basicHomeCost, profit, COST_PER_SQUARE_FT, optionalFeatures, PERCENT_PROFIT, discount, taxes, STATE_TAX_RATE); 

//Display result     
displaySummary(basicHomeCost, optionalFeatures, discount, totalHomeCost);

//Display end
displayNumberDone(i);

}

//Display goodbye
displayGoodbye();
     
return 0;

}//end of the main function


Since I don't know what functions you want in the loop, I simply placed it just before the call to displayGoodbye(); . Now that should make your code work.
Topic archived. No new replies allowed.