Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VHB C++ DE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VHB Cpp
VHB C++ DE
Commits
23119022
Commit
23119022
authored
7 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 3 - Guessing numbers.cpp
parent
8f68e61a
No related branches found
Branches containing commit
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Part 1/4. Control structures/Solutions/Solution Exercise 3 - Guessing numbers.cpp
+19
-25
19 additions, 25 deletions
...ures/Solutions/Solution Exercise 3 - Guessing numbers.cpp
with
19 additions
and
25 deletions
Part 1/4. Control structures/Solutions/Solution Exercise 3 - Guessing numbers.cpp
+
19
−
25
View file @
23119022
#include
<iostream>
#include
<ctime>
#include
<iostream>
using
namespace
std
;
int
main
()
{
int
number
,
input
,
tries
=
0
;
srand
(
time
(
NULL
));
number
=
rand
()
%
100
+
1
;
// Random number between 0 and 99 is generated, therefore +1, so that the number is between 1 and 100
do
{
cout
<<
"Input a number: "
;
cin
>>
input
;
if
(
input
>
number
)
cout
<<
"Too large!"
<<
endl
;
if
(
input
<
number
)
cout
<<
"Too small!"
<<
endl
;
tries
++
;
}
while
(
input
!=
number
&&
tries
<
6
);
int
main
()
{
int
number
,
input
,
tries
=
0
;
srand
(
time
(
NULL
));
number
=
rand
()
%
100
+
1
;
//Random number between 0 and 99 is generated, therefore +1, so that the number is between 1 and 100
if
(
input
==
number
)
cout
<<
"You guessed the right number!"
<<
endl
;
else
cout
<<
"You lost! The number was "
<<
number
<<
endl
;
do
{
cout
<<
"Input a number: "
;
cin
>>
input
;
if
(
input
>
number
)
cout
<<
"Too large!"
<<
endl
;
if
(
input
<
number
)
cout
<<
"Too small!"
<<
endl
;
tries
++
;
}
while
(
input
!=
number
&&
tries
<
6
);
if
(
input
==
number
)
cout
<<
"You guessed the right number!"
<<
endl
;
else
cout
<<
"You lost! The number was "
<<
number
<<
endl
;
return
0
;
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment