how to make a loop with menu

im trying to put a simple menu at the end of the program that gives the user the option to repeat the program, it a proyect for my class XDXDXDXD so it can only be done using FOR, WHILE, DO-WHILE, SWITCH, <CMATH> AND other simple functions, this code is used to calculate how many dollars of 100, 50, 20, 10, 5, 1 i can use until i get to the amount specified by the user. appreciated the help SORRY IS IN SPANISH THE MENU MENU IS IN ENGLISH DO XD

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
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double cant; 
    int A, B, C, D, E, F, totalA, totalB, totalC, totalD, totalE, totalF;
    do
    {
    cout<<"Ingrese la cantidad que desea pagar:\n";
    cin>>cant;
    }
    while(cant<0);
    {
     if(cant>100)
     {
      A=cant/100;
      totalA=A*100-cant;
      B=totalA/50;
      totalB=B*50-totalA;
      C=totalB/20;
      totalC=C*20-totalB;
      D=totalC/10;
      totalD=D*10-totalC;
      E=totalD/5;
      totalE=E*5-totalD;
      F=totalE/1;
      totalF=F*1-totalE;
      
      cout<<"Su cantidad a pagar:\n";
      cout<<"En billetes de 100 es de                    :"<<A<<"\n";
      cout<<"En billetes de 50 es de                     :"<<B<<"\n";
      cout<<"En billetes de 20 es de                     :"<<C<<"\n";
      cout<<"En billetes de 10 es de                     :"<<D<<"\n";
      cout<<"En billetes de  5 es de                     :"<<E<<"\n";
      cout<<"En billetes de  1 es de                     :"<<F<<"\n";  
      }
      else if(cant<=99 && cant>=50)
      {
      A=cant/50;
      totalA=A*50-cant;
      B=totalA/20;
      totalB=B*20-totalA;
      C=totalB/10;
      totalC=C*10-totalB;
      D=totalC/5;
      totalD=D*5-totalC;
      E=totalD/1;
      totalE=E*1-totalD;
      
      
      cout<<"Su cantidad a pagar:\n";
      cout<<"En billetes de 50 es de                     :"<<A<<"\n";
      cout<<"En billetes de 20 es de                     :"<<B<<"\n";
      cout<<"En billetes de 10 es de                     :"<<C<<"\n";
      cout<<"En billetes de  5 es de                     :"<<D<<"\n";
      cout<<"En billetes de  1 es de                     :"<<E<<"\n";    
      }  
      else if(cant<=49 && cant>=20)
      {
      A=cant/20;
      totalA=A*20-cant;
      B=totalA/10;
      totalB=B*10-totalA;
      C=totalB/5;
      totalC=C*5-totalB;
      D=totalC/1;
      totalD=D*1-totalC;
      
      cout<<"Su cantidad a pagar:\n";
      cout<<"En billetes de 20 es de                     :"<<A<<"\n";
      cout<<"En billetes de 10 es de                     :"<<B<<"\n";
      cout<<"En billetes de  5 es de                     :"<<C<<"\n";
      cout<<"En billetes de  1 es de                     :"<<D<<"\n";
      }
      else if(cant<=19 && cant>=10)
      {
      A=cant/10;
      totalA=A*10-cant;
      B=totalA/5;
      totalB=B*5-totalA;
      C=totalB/1;
      totalC=C*1-totalB;
      
      cout<<"Su cantidad a pagar:\n";
      cout<<"En billetes de 10 es de                     :"<<A<<"\n";
      cout<<"En billetes de  5 es de                     :"<<B<<"\n";
      cout<<"En billetes de  1 es de                     :"<<C<<"\n";
      }
      else if(cant<=9 && cant>=1)
      {
      A=cant/5;
      totalA=A*5-cant;
      B=totalA/1;
      totalB=B*1-totalA;
      
      cout<<"Su cantidad a pagar:\n";
      cout<<"En billetes de  5 es de                     :"<<A<<"\n";
      cout<<"En billetes de  1 es de                     :"<<B<<"\n";
      }
      else
      cout<<"nose\n";
       
      }
      system("pause");
      return 0;
}
Last edited on
Removed 2 braces. Please add in case functionality has changed. I don't know Spanish. Courtesy Google Language Tools :)

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
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double cant; 
    char eleccion = 'n';
    int A, B, C, D, E, F, totalA, totalB, totalC, totalD, totalE, totalF;
	do
	{
		do
		{
			cout<<"Ingrese la cantidad que desea pagar:\n";
			cin>>cant;
		}
		while(cant<0);

		if(cant>100)
		{
		  A=cant/100;
		  totalA=A*100-cant;
		  B=totalA/50;
		  totalB=B*50-totalA;
		  C=totalB/20;
		  totalC=C*20-totalB;
		  D=totalC/10;
		  totalD=D*10-totalC;
		  E=totalD/5;
		  totalE=E*5-totalD;
		  F=totalE/1;
		  totalF=F*1-totalE;
      
		  cout<<"Su cantidad a pagar:\n";
		  cout<<"En billetes de 100 es de                    :"<<A<<"\n";
		  cout<<"En billetes de 50 es de                     :"<<B<<"\n";
		  cout<<"En billetes de 20 es de                     :"<<C<<"\n";
		  cout<<"En billetes de 10 es de                     :"<<D<<"\n";
		  cout<<"En billetes de  5 es de                     :"<<E<<"\n";
		  cout<<"En billetes de  1 es de                     :"<<F<<"\n";  
		}

		else if(cant<=99 && cant>=50)
		{
		  A=cant/50;
		  totalA=A*50-cant;
		  B=totalA/20;
		  totalB=B*20-totalA;
		  C=totalB/10;
		  totalC=C*10-totalB;
		  D=totalC/5;
		  totalD=D*5-totalC;
		  E=totalD/1;
		  totalE=E*1-totalD;
      
      
		  cout<<"Su cantidad a pagar:\n";
		  cout<<"En billetes de 50 es de                     :"<<A<<"\n";
		  cout<<"En billetes de 20 es de                     :"<<B<<"\n";
		  cout<<"En billetes de 10 es de                     :"<<C<<"\n";
		  cout<<"En billetes de  5 es de                     :"<<D<<"\n";
		  cout<<"En billetes de  1 es de                     :"<<E<<"\n";    
		}
		
		else if(cant<=49 && cant>=20)
		{
		  A=cant/20;
		  totalA=A*20-cant;
		  B=totalA/10;
		  totalB=B*10-totalA;
		  C=totalB/5;
		  totalC=C*5-totalB;
		  D=totalC/1;
		  totalD=D*1-totalC;
      
		  cout<<"Su cantidad a pagar:\n";
		  cout<<"En billetes de 20 es de                     :"<<A<<"\n";
		  cout<<"En billetes de 10 es de                     :"<<B<<"\n";
		  cout<<"En billetes de  5 es de                     :"<<C<<"\n";
		  cout<<"En billetes de  1 es de                     :"<<D<<"\n";
		}

		else if(cant<=19 && cant>=10)
		{
		  A=cant/10;
		  totalA=A*10-cant;
		  B=totalA/5;
		  totalB=B*5-totalA;
		  C=totalB/1;
		  totalC=C*1-totalB;
      
		  cout<<"Su cantidad a pagar:\n";
		  cout<<"En billetes de 10 es de                     :"<<A<<"\n";
		  cout<<"En billetes de  5 es de                     :"<<B<<"\n";
		  cout<<"En billetes de  1 es de                     :"<<C<<"\n";
		}

		else if(cant<=9 && cant>=1)
		{
		  A=cant/5;
		  totalA=A*5-cant;
		  B=totalA/1;
		  totalB=B*1-totalA;
      
		  cout<<"Su cantidad a pagar:\n";
		  cout<<"En billetes de  5 es de                     :"<<A<<"\n";
		  cout<<"En billetes de  1 es de                     :"<<B<<"\n";
		}

		else
		 cout<<"nose\n";

		cout<<endl<<"Te gustaria repetir? Pulse 'y' para seguir mas de prensa de cualquier otro alfabeto para salir: ";
		cin>>eleccion;		
	}
	while(eleccion == 'y' || eleccion == 'Y');

    system("pause");
    return 0;
}
Last edited on
hi mate, you should do what i do, wrap the code in a while, and then give option to repeat, like this:

1
2
3
4
5
6
char X='Y';
while(X=='y'||X=='Y'){
ALL UR PROGRAM
cout<<"\n\nDesea realizar otra operacion? (Y/N) ";
cin>>X;
}


that way u ask everytime the program finishes if u want to repeat it, and it will as long as X is equal to 'y' or 'Y'

hope it helps
thats a good idea, Y/N, by the way THE PROGRAM WORKED lol tanxz for the help XD, (Courtesy Google Language Tools)lololololololol
Topic archived. No new replies allowed.