error: character constant too long for its type In function 'int main()':

Hello,
I started making a program that would convert your test results into a percentage, making snide remarks on your grade. I ran it through codepad.org, and I got an error at line 18, which was a blank space. Here's the code itself:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>


int main()
{
	do
	{

	bool onemore;
	onemore == true;
	char yesno;
	yesno  == 'y';

	float total;
	std::cout << "What was the test out of? ";
	std::cin >> total;
	

	float mark;
	std::cout << "What did you get? ";
	std::cin >> mark;
	
	float totalonehundred;
	totalonehundred == (mark / total) * 100;
	
	if (totalonehundred >= 100.01)
	std::cout << "\nNice try, Putin.\n";



	if (totalonehundred >= 60 )
		{
	if (totalonehundred >= 75)
			{
	if (totalonehundred >= 85)
				{
	if (totalonehundred >= 95)
					{
	if (totalonehundred ==100)
						{
	std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
	return 0;
			
		}
	
	
	std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
	return 0;
	
			}	
	
	
	std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
	return 0;
				}		
	
	std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
	return 0;
					}				
	
	
	std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
	return 0;
	
						}					
	
	


	if (totalonehundred <=60)
	std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";



	std::cout << "\n Start over? Y/N \n";
	std::cin >> yesno;
	if ( yesno == 'y')
	{ onemore == true;
	return 0;
	}

	if ( yesno == 'n')
	{ onemore == false;
	} 

while (onemore != 'flase')
				
}


It's been driving me absolutely bonkers. It's probably super-obvious too, I'm just not seeing it at the moment. If you could help me out, I would be much obliged!
Thiese are not assignments but comparisions

onemore == true;
yesno == 'y';

I think that the error message was generated by this statement

while (onemore != 'flase')

The character literal 'flase' is indeed too long that to be converted to int.:)
Last edited on
This is also wrong
totalonehundred == (mark / total) * 100;

and this

if (totalonehundred ==100)


Vlad is right you should just use one '=', you use two for comparisons.
Last edited on
OK, so I did this, but it's still giving me errors. Here:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>


int main()
{
	do
	{

	bool onemore;
	onemore == true;
	char yesno;
	yesno  == 'y';

	float total;
	std::cout << "What was the test out of? ";
	std::cin >> total;
	

	float mark;
	std::cout << "What did you get? ";
	std::cin >> mark;
	
	float totalonehundred;
	totalonehundred = (mark / total) * 100;
	
	if (totalonehundred >= 100.01)
	std::cout << "\nNice try, Putin.\n";



	if (totalonehundred >= 60 )
		{
	if (totalonehundred >= 75)
			{
	if (totalonehundred >= 85)
				{
	if (totalonehundred >= 95)
					{
	if (totalonehundred =100)
						{
	std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
	return 0;
			
		}
	
	
	std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
	return 0;
	
			}	
	
	
	std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
	return 0;
				}		
	
	std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
	return 0;
					}				
	
	
	std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
	return 0;
	
						}					
	
	


	if (totalonehundred <=60)
	std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";



	std::cout << "\n Start over? Y/N \n";
	std::cin >> yesno;
	if ( yesno = 'y')
	{ onemore = true;
	return 0;
	}

	if ( yesno = 'n')
	{ onemore = false;
	} 

while (onemore != 'flase')
				
}


But now it's giving me this:
Line 18: error: character constant too long for its type
cc1plus: warnings being treated as errors
In function 'int main()':
Line 39: warning: suggest parentheses around assignment used as truth value
Line 77: warning: suggest parentheses around assignment used as truth value
Line 82: warning: suggest parentheses around assignment used as truth value
Line 88: error: expected primary-expression before '}' token
compilation terminated due to -Wfatal-errors.


Any ideas?
I do not see that what I pointed out was changed.
line 12: yesno = 'y';
line 39: if (totalonehundred ==100)
line 77: if ( yesno == 'y')
line 82: if ( yesno == 'n')
line 86: while (onemore != false);

Plus there might be [some] } missing, but the indention makes it hard to tell
Last edited on
Vlad,
I changed the (yesno == 'y')
to (yesno = 'y') It's still giving me errors though.
Vlad is right you haven't changed the initialisations

1
2
3
4
bool onemore;
onemore == true;
char yesno;
yesno  == 'y';


to

1
2
3
4
bool onemore;
onemore = true;
char yesno;
yesno  = 'y';


Also it still says 'flase' on that last while loop.

This isn't exactly rocket surgery.
Sorry. It's still early for me. I did the small corrections, but it still complains:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>


int main()
{
	do
	{

	bool onemore;
	onemore = true;
	char yesno;
	yesno  = 'y';

	float total;
	std::cout << "What was the test out of? ";
	std::cin >> total;
	

	float mark;
	std::cout << "What did you get? ";
	std::cin >> mark;
	
	float totalonehundred;
	totalonehundred = (mark / total) * 100;
	
	if (totalonehundred >= 100.01)
	std::cout << "\nNice try, Putin.\n";



	if (totalonehundred >= 60 )
	{
	if (totalonehundred >= 75)
	{
	if (totalonehundred >= 85)
	{
	if (totalonehundred >= 95)
	{
	if (totalonehundred =100)
	{
	std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
	return 0;	
	}
	
	
	std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
	return 0;
	}	
	
	
	std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
	return 0;
	}		
	
	std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
	return 0;
	}				
	
	
	std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
	return 0;
	}					
	
	


	if (totalonehundred <=60)
	std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";



	std::cout << "\n Start over? Y/N \n";
	std::cin >> yesno;
	if ( yesno = 'y');
	{ onemore = true;
	return 0;
	}

	if ( yesno = 'n');
	{ onemore = false;
	return 0;
	} 

while (onemore != false)
				
}


Now it says:

cc1plus: warnings being treated as errors
In function 'int main()':
Line 39: warning: suggest parentheses around assignment used as truth value
Line 74: warning: suggest parentheses around assignment used as truth value
Line 79: warning: suggest parentheses around assignment used as truth value
Line 86: error: expected primary-expression before '}' token
compilation terminated due to -Wfatal-errors.


edit: cleaned up a bit, for your sake.
Last edited on
Why do not you want to do anything yourself? Switch on you brain.

Check everywhere whether you correctly placed the comparision operator ==
Example: Lines 74 and 79 should use double ==, which you have wrong, and lines 75 and 80 should use single =, which you have correct.
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>


int main()
{
bool onemore;
	do
	{
	onemore = true;
	char yesno;
	yesno  = 'y';

	float total;
	std::cout << "What was the test out of? ";
	std::cin >> total;
	

	float mark;
	std::cout << "What did you get? ";
	std::cin >> mark;
	
	float totalonehundred;
	totalonehundred = (mark / total) * 100;
	
	if (totalonehundred >= 100.01)
	std::cout << "\nNice try, Putin.\n";



	if (totalonehundred >= 60 )
	{
			if (totalonehundred >= 75)
			{
				if (totalonehundred >= 85)
				{
					if (totalonehundred >= 95)
					{
						if (totalonehundred =100)
						{
						std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
						return 0;
			
						}
	
	
					std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
					return 0;
	
					}	
	
	
	std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
	return 0;
				}		
	
	std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
	return 0;
							
	
	
	std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
	return 0;
	
		}					
	
	


	if (totalonehundred <=60)
	std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";



	std::cout << "\n Start over? Y/N \n";
	std::cin >> yesno;
	if ( yesno == 'y'){ 
		onemore = true;
	}

	if ( yesno == 'n'){
		onemore = false;
		return 0;
	} 

				
	}
}while (onemore != false);
}


No compile time errors but it still wont run the way you want...try yourself
Last edited on
Lethal,
I tried your version, and first of all thank you for helping me. I've spent so long on this program.

I think I found out what's wrong - at line 59 I think there's a '}' missing. I'll try putting it in and running it next chance I get.
Last edited on
So I tested a slightly tweaked version of Lethal's code, and it seemed to work only when I failed a test. I noticed that when I have it make a comment, at the end it says
return 0;
. That might be stopping it from activating the "start over?" loop. I got rid of it, and here is the code now:
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
 
 
int main()
{
bool onemore;
    do
        {
        onemore = true;
        char yesno;
        yesno  = 'y';
 
        float total;
        std::cout << "What was the test out of? ";
        std::cin >> total;
        
 
        float mark;
        std::cout << "What did you get? ";
        std::cin >> mark;
        
        float totalonehundred;
        totalonehundred = (mark / total) * 100;
        
        if (totalonehundred >= 100.01)
        {	std::cout << "\nNice try, Putin.\n";
 
 	}
 
        if (totalonehundred >= 60 )
        {
		if (totalonehundred >= 75)
                {
			if (totalonehundred >= 85)
                        {
                        	if (totalonehundred >= 95)
                                {
                                	if (totalonehundred =100)
                                        {
                                        std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
                                        
                        
                                        }
        
        
                                std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
                                
        
                                }       
        
        
       			std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
        		
                        }               
        
        	std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
       		
                                                        
        	}
        
        std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
        
        
        }                                       
        
        
 
 
        if (totalonehundred <=60)
        {std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";
 	}
 
 
        std::cout << "\n Start over? Y/N \n";
        std::cin >> yesno;
        if ( yesno == 'y'){ 
                onemore = true;
        }
 
        if ( yesno == 'n'){
                onemore = false;
                return 0;
        } 
 
                                
        }
}while (onemore != false);
}


But, of course, it couldn't be that simple. Now it complains like this:
 prog.cpp: In function 'int main()':
prog.cpp:87: error: expected `while' before '}' token
prog.cpp:87: error: expected `(' before '}' token
prog.cpp:87: error: expected primary-expression before '}' token
prog.cpp:87: error: expected `)' before '}' token
prog.cpp:87: error: expected `;' before '}' token
prog.cpp: At global scope:
prog.cpp:87: error: expected unqualified-id before 'while'
prog.cpp:88: error: expected declaration before '}' token

Any ideas?

Note: when I said 'work' at the top, I meant: do the calculation, give you the percent, snide comment, then it asks for another test. If 'y' was entered, it would start over. if 'n' was entered, it would close.
Last edited on
Topic archived. No new replies allowed.