Functions

Hello,everyone! I have to write a program that check if a string contains only allowed symbols like
+, -, *, / and (), [], {} using a function and I need your help.
You need to loop through all the chars in the string.
If the char is not allowed return false.
After the loop return true.
A starting point:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

using namespace std;

bool valid_string(const string& input)
{
  // place your code here
}

int main()
{
  string input;
  cout << "Enter string to test: ";
  getline(cin, input);
  bool valid = valid_string(input);
  if (valid)
    cout << "valid";
  else
    cout << "Not valid";
}
think about the process you would do this on pen and paper. Then code it.

hint: this will help you a lot
http://www.cplusplus.com/reference/string/string/size/
Last edited on
Registered users can post here. Sign in or register to post.