Second beginner task assignment done- simplify?

So this is the second beginner task

--------------------------------------------------------------------------------

Cola Machine
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)

Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water, Sprite, ... , Whatever).
Then allow the user to choose a beverage by entering a number 1-5.
Output which beverage they chose.

★ If you program uses if statements instead of a switch statement, modify it to use a switch statement.
If instead your program uses a switch statement, modify it to use if/else-if statements.

★★ Modify the program so that if the user enters a choice other than 1-5 then it will output "Error. choice was not valid, here is your money back."

-------------------------------------------------------------------------------

*And I know my solution is somewhat elaborate and very "noobish" and is as follows*
-------------------------------------------------------------------------------


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
// Cola Machine

#include "stdafx.h"
#include <windows.h>
#include <iostream>

using namespace std;

int main()

{
	start:
	int x;
	int y;
	cout<<"***********************************************************************"<<endl;
	cout<<"**                                                                   **"<<endl;
	cout<<"** Hello Refreshin' Drinks at your service                           **"<<endl;
	cout<<"**                                                                   **"<<endl;
	cout<<"** Press the relevent number to select a drink you wish to purchase: **"<<endl;
	cout<<"**                                                                   **"<<endl;
	cout<<"***********************************************************************"<<endl;

	cout<<endl;
	cout<<"******************************"<<endl;
	cout<<"**----------------|---------**"<<endl;
	cout<<"**  Cola          | Press 1 **"<<endl;
	cout<<"**----------------|---------**"<<endl;
	cout<<"**  Fanta         | Press 2 **"<<endl;
	cout<<"**----------------|---------**"<<endl;
	cout<<"**  Sprite        | Press 3 **"<<endl;
	cout<<"**----------------|---------**"<<endl;
	cout<<"**  Soda pop      | Press 4 **"<<endl;
	cout<<"**----------------|---------**"<<endl;
	cout<<"**  Lukazadeeeeeee| Press 5 **"<<endl;
	cout<<"**----------------|---------**"<<endl;
	cout<<"******************************"<<endl;
	cout<<endl;
	cout<<"Selection?-";
	cin>> x ;
	cin.ignore();

	if (x == 1){
		cout<<endl;
		cout<<"Cola coming up"<<endl;
		Sleep(1000);
	goto end;}
	
	else if (x == 2){
		cout<<endl;
		cout<<"Fanta coming up"<<endl;
		Sleep(1000);
	goto end;}
	
	else if (x ==3){
		cout<<endl;
		cout<<"Sprite coming up"<<endl;
		Sleep(1000);
	goto end;}
	
	else if (x == 4){
		cout<<endl;
		cout<<"Soda pop coming up"<<endl;
		Sleep(1000);
	goto end;}
	
	else if (x == 5){
		cout<<endl;
		cout<<"Lukazadeeeeeee coming up"<<endl;
		Sleep(1000);
	goto end;}
	
	
	else 
	
	{
		cout<<endl;
		cout<<"--Error, choice was not valid--"<<endl;
		Sleep(1000);
		cout<<endl;
		cout<<"Press 1 and Enter to exit and get your money back,\nPress 2 and Enter to start selection again"<<endl;
		cin>> y;
		
	if (y == 1) 
		goto end;
		
	else if (y == 2)
		goto start;
	}
	
	end:
	
	cout<<endl;

	cout<<"T";
	Sleep(100);
	cout<<"h";
	Sleep(100);
	cout<<"a";
	Sleep(100);
	cout<<"n";
	Sleep(100);
	cout<<"k";
	Sleep(100);
	cout<<" ";
	Sleep(100);
	cout<<"y";
	Sleep(100);
	cout<<"o";
	Sleep(100);
	cout<<"u";
	Sleep(100);
	cout<<" ";
	Sleep(100);
	cout<<"h";
	Sleep(100);
	cout<<"a";
	Sleep(100);
	cout<<"v";
	Sleep(100);
	cout<<"e";
	Sleep(100);
	cout<<" ";
	Sleep(100);
	cout<<"a";
	Sleep(100);
	cout<<" ";
	Sleep(100);
	cout<<"n";
	Sleep(100);
	cout<<"i";
	Sleep(100);
	cout<<"c";
	Sleep(100);
	cout<<"e";
	Sleep(100);
	cout<<" ";
	Sleep(100);
	cout<<"d";
	Sleep(100);
	cout<<"a";
	Sleep(100);
	cout<<"y";
	Sleep(100);

	cin.get();
}


-------------------------------------------------------------------------------

So forgetting the goto mechanism I've implemented as I have just found out how to do loops and use them which I have not updated in this program yet....

What I want to know is how would the cout "letter" then sleep (time) rinse and repeat be written more streamline... for instance a code that writes a sentence or phrase char by char with delay without manually having to do it... or is this the quickest way?
closed account (D80DSL3A)
This should work:
1
2
3
4
5
6
7
const char* message = "Thank you have a nice day";
int i=0;
while( message[i] != '\0' )
{
    cout << message[i++];
    Sleep(100);
}
Thanks alot... the code works perfectly and whats more I can actually read through it and understand it too... one quick question ive added it instead of the long manual version at the bottom of my program, but a thing I forgot to mention last time is that there seems to be a bug already in such a short program....

Whereas when using the program and inputting an invalid number, then selecting 1 to exit, when it shows the text "Thank you have a nice day" it doesn't hang afterwards waiting for user input such as enter and immediately closes... everything else seems to be working as written! any Ideas?

Thanks fun2code, it's a great little code to learn.
Topic archived. No new replies allowed.