If statement explained/code written

This commit is contained in:
Mert Gör 🇹🇷 2024-06-30 02:24:24 +03:00
parent 2b2613c101
commit c40c2b4ae9
Signed by: hwpplayer1
GPG Key ID: 03E547D043AB6C8F
2 changed files with 32 additions and 0 deletions

View File

@ -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> 2024-06-24 hwpplayer1 <hwpplayer1@debian>
* src/for_example_2.cpp: another for example * src/for_example_2.cpp: another for example

28
src/if_statement.cpp Normal file
View 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;
}