How to stop a for loop from incrementing but not stopping the loop entirely?

It's a difficult question to describe but, I want the maximum amount of times my for loop to increment something to be 5 times, but I want it to continue looping the 5th iteration so it repeats letting the user know 5 is the maximum amount of times, and every time that uses chooses to iterate the loop on my switch menu it won't iterate any further than 5.

I have an idea of what the for loop should look like, but i'm lost as to how I should make the conditional while statement look that sets the boundaries.

Or use a empty for loop

PS: Don't you love your PC? Why are you trying to fry it?
Lol I don't mean an infinite loop, just user controlled increment and at 5 it'll just repeat what the value of 5 is each time they choose that option to increment it
oh, can you show us your code and the output you are expecting?
I mean it's a whole chunk of code so i'll just post one of the functions that has the loop

The user is supposed to enter 1 and it will upgrade once, the first upgrade cost should be 100, if they enter 1 again it'll become engine level 2 and become 300, engine level 3 600, engine level 4, 1000, engine level 5 1500. Once it reaches engine level 5 it should stop incrementing. If they put -1, it should go back to the previous upgrade cost and engine level, the least being 0. I just don't know how to get the calculation or loop that sets that boundary right.. I'm only having trouble on my switch statement case 1 and -1.

Here's the code:

int modMenu(int choice, int carCost, int engineLevel, int upgradeCost, int quoteNumber)
{
int Total = 0;
choice = 0;
engineLevel = 0;
const int hundred = 100;

while(choice != 4)
{
cout<<"Do you want to upgrade your car?"<<endl;
cout<<"[-/+1] Downgrade / Upgrade Engine"<<endl;
cout<<"[ 2] Clear all upgrades"<<endl;
cout<<"[ 3] Reset car"<<endl;
cout<<"[ 4] Buy Car!!!"<<endl;
cout<<"What would you like to do?: ";
cin>>choice;

switch(choice)
{
case 1:
engineLevel++;
for(int counter = 1; counter < engineLevel; counter++)
{
upgradeCost+= counter * hundred;
}
break;
case -1:
engineLevel--;
for(int counter = 1; counter <= engineLevel; counter++)
{
upgradeCost-= counter * hundred;
}
break;
case 2:
engineLevel = 0;
upgradeCost = 0;
break;
case 3:
cout<<endl;
return main();
break;
case 4:
Total = carCost + upgradeCost;
cout<<showpoint<<setprecision(2)<<fixed<<endl;
cout <<"Bill:";
cout << " Car($" << static_cast<double>(carCost) << ")";
cout << " Upgrades($" << static_cast<double>(upgradeCost) << ") ";
cout << "Total ($"<<static_cast<double>(Total)<<")"<<endl;
cout << "Press ENTER to continue";
cin.ignore();
cin.get();
break;
}
cout<<showpoint<<setprecision(2)<<fixed<<endl;
cout<< "{" << quoteNumber++ << "} ";
cout << " Car($" << static_cast<double>(carCost) << ")";
cout << " E(" << engineLevel << ")";
cout << " Upgrades($" << static_cast<double>(upgradeCost) << ")" << endl;
}
Something like this maybe?

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
#include <iostream>
#include <string>

int main() {

	const int max_value = 5;
	const int min_value = 0;

	const std::string message_terminate = "quit";
	const std::string message_increment = "1";
	const std::string message_decrement = "-1";

	std::string input;
	int value = 0;

	std::cout << "Enter \"1\" to increment, enter \"-1\" to decrement (\"" << message_terminate << "\" to quit):\t";

	while (true) {

		std::getline(std::cin, input);
		if (input == message_terminate) {
			break;
		}
		else if (input == message_increment) {
			
			if (value == max_value) {
				std::cout << "Value has reached maximum capacity (" << max_value << ")." << std::endl;
			}
			else {
				std::cout << "Value:\t" << ++value << std::endl;
			}

		}
		else if (input == message_decrement) {
			
			if (value == min_value) {
				std::cout << "Value has reached minimum capacity (" << min_value << ")." << std::endl;
			}
			else {
				std::cout << "Value:\t" << --value << std::endl;
			}

		}
		else {
			std::cout << "Try again:\t";
		}

	}

	return 0;
}
Topic archived. No new replies allowed.