If statement explained/code written
This commit is contained in:
		@@ -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;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user