If statement explained/code written
This commit is contained in:
parent
2b2613c101
commit
c40c2b4ae9
2 changed files with 32 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
2024-06-30 hwpplayer1 <hwpplayer1@debian>
|
||||
|
||||
* src/if_statement.cpp: if statement explained/code written
|
||||
|
||||
2024-06-24 hwpplayer1 <hwpplayer1@debian>
|
||||
|
||||
* src/for_example_2.cpp: another for example
|
||||
|
|
28
src/if_statement.cpp
Normal file
28
src/if_statement.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
int currVal = 0, val = 0;
|
||||
|
||||
if (std::cin >> currVal)
|
||||
{
|
||||
int cnt = 1;
|
||||
while (std::cin >> val)
|
||||
{
|
||||
if (val == currVal)
|
||||
{
|
||||
++cnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << currVal << " occurs "
|
||||
<< cnt << " times " << std::endl;
|
||||
currVal = val;
|
||||
cnt = 1;
|
||||
}
|
||||
}
|
||||
std::cout << currVal << " occurs "
|
||||
<< cnt << " times " << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue