Couting more than it should.

Oct 28, 2018 at 3:42pm
Can anyone tell me why my function is couting way more outputs than there are if statements? It doesn't seem possible.
All I need are the characters described in my if statements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  #include <string>
using namespace std;

char punk()
{
    char pun;
    for(char i='!'; i<='~'; i++){
        pun=i;
    
    
     //!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
    

    if (pun == '.'){
    cout << "-+-+++- ";
    }
    if (pun == ','){
        cout << "-+-++-- ";
    }
    if (pun == ':'){
        cout << "-+++-+- ";
    }
    if(pun == '?'){
        cout << "-++++++ ";
    }
    if(pun == '\''){
        cout << "-+--+++ ";
    }
    if(pun == '_'){
        cout << "-+-++-+ ";
    }
    if(pun == '/'){
        cout << "-+-++++ ";
    }
    if(pun = '"'){
        cout << "-+-+-++ ";
    }
    if(pun == '@'){
        cout << "+------ ";
    }}
    return pun;
    
}
Oct 28, 2018 at 3:48pm
if(pun = '"'){

You're doing an assignment here. Use two equal signs.

Also please fix your indenting. It's very misleading. Everything inside your for loop should be indented past it.
Topic archived. No new replies allowed.