How do i loop the same amount of times user wants it to?

Hi im new to C++ programming. How do i make my code loop as per the user input in the “Enter how many items you want to buy” part? Like if the user inputs 2, then it will loop 2 times or 4, then it will loop 4 times.

This is my code so far

//Q3 TRY AGAIN
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	int num_prod, prod_code, prod_qtt, loop = 0, count;
	float total = 0, final = 0;
	cout<<"--------------------------------------------\n";
	cout<<" (1)    Cooking oil            RM2.50\n";
	cout<<" (2)    Curry powder           RM3.40\n";
	cout<<" (3)    Detergent              RM8.50\n";
	cout<<" (4)    Potato chips           RM3.20\n";
	cout<<"---------------------------------------------\n";
	cout<<"Enter number of product that you want to purchase (press 0 to exit) : ";
	cin>>num_prod;
	
	do
	{
		loop++;
		cout<<loop<<"."<<"Enter Item's Code : ";
		cin>>prod_code;
		cout<<loop<<"."<<"Enter the quantity of item you want to buy : ";
		cin>>prod_qtt;
	}while(prod_code != 0);
	
	
	switch(prod_code)
	{
		case 1 :
			total = (5.0/2)*prod_qtt;
			count = 1;
			break;
		case 2 :
			total = (17.0/5)*prod_qtt;
			count = 2;
			break;
		case 3 :
			total = (17.0/2)*prod_qtt;
			count = 3;
			break;
		case 4 :
			total = (16.0/5)*prod_qtt;
			count = 4;
			break;
	}
	
	if(count <= 4);
	{
	  final += total;
	}
    
    cout<<"Total price is RM"<<final;
	
	
	return 0;
	
	
	
}

Welcome to the form!

Are you familiar with for loops?

for (int i = 0; i < num_prod; i++) {
  // Buying the stuff code
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank you!! and yes, im familiar with loops :slight_smile: