mail@pastecode.io avatar
2 years ago
1.4 kB
// Created by Tammar Shrot on 05/12/2022.
#include <iostream>

#define END_MARK '!'
#define BAD_MARK '%'

 * This program will get characters from the users (without enter between them...)
 * It will print every char on the screen, until it reach the char '!' which mark the end of the input.
 * Unless it will see the char '%' which will make it stop processing the input and just input it till the end.
int main() {
    char ch; //for input
    bool isValid = true;//our flag if we should still process the input
    std::cout <<"Enter characters. End with the '"<< END_MARK <<"' char." << std::endl;//informing the user
        std::cin >> ch;//input

        if (isValid) {//if we should process the input
            if (ch == BAD_MARK)//make sure to update the flag if no longer need to process
                isValid = false;
            else//everything still valid
                std::cout<< ch;//process
    }while(ch != END_MARK);//end of loop when we get to the end mark

    //one more input & output just to show everything is as it should be:
    std::cout<<std::endl <<"enter another char." << std::endl;//inform
    std::cin >> ch;//get input
    std::cout << ch;//output
    return 0;
}//wasn't that hard, right?
//now try to replace the cout inside the loop with a function that actually does something.