Example
#{example}"); ipb.editor_values.get('templates')['togglesource'] = new Template(""); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
Emoticons
"); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]5 Replies - 33 Views - Last Post: 3 minutes ago
#1
Reputation: 0
- Posts: 7
- Joined: 02-April 13
Posted Yesterday, 09:25 PM
Hey guys, so if you guys saw my post a little while back I am writing a program that takes in 10 digit ISBN numbers in the form of strings, I then check the ISBN to see if its valid, and then i print out if it is valid or not. Basically, if an 'X' appears in the ISBN as the last digit, it is supposed to assign that index in the array to the value of 10, and if 'X' is any where else in the array the ISBN is invalid. Here is My code:#include <iostream> #include <string> using namespace std; int main() { int keep = 0; string isbn[20]; do{ cin >> isbn[keep]; } while (isbn[keep][0] != 4 && keep++ < 20); for (int i = 0; i < keep; i++){ //looping through all of the strings int save = 0; int partial[10]; for (int k = 0; k < isbn[i].length(); k++){ //looping through all of the characters if ((isbn[i][k] >= '0' && isbn[i][k] <= '9') || (save == 10 && isbn[i][k] == 'X')){ //checking if ISBN is valid int next = 0; if (isbn[i][k] == 'X') partial[save] = 10; else next = (int)(isbn[i][k] - '0'); if (save == 0) partial[save] = next; else partial[save] = partial[save-1] + next; save++; } else if (isbn[i][k] != '-'){ cout << isbn[i][k] << " is not valid" << endl; break; } } int use = partial[0]; for (int j = 0; j < 9; j++){ use += partial[j + 1]; } if (use % 11 == 0){ cout << isbn[i] << " is valid." << endl; } else cout << isbn[i] << " is not valid" << endl; } }
Basically, it works for all ISBN's except for the ISBN's with the X as the last digit. It will just print out X is invalid, so for some reason it isn't getting picked up in my big if statement. What do you guys think is causing this issue? Could it be that it is just reading the first part of the if and not looking at the second part of the if statement? I tried changing it to save == 9, and this time it doesnt print out X is invalid, but still says that the isbn number is invalid. Two ISBN's you guys can try are 0 1 3 1 6 2 9 5 9 X or 0-1315-2447-X (dashed don't matter).
Thanks!
Is This A Good Question/Topic? 0
Replies To: Problem with reading character 'X' from array
#2
Reputation: 0
- Posts: 7
- Joined: 02-April 13
Re: Problem with reading character 'X' from array
Posted Yesterday, 09:38 PM
(and if you are testing the code and wondering how to stop entering the ISBN's, type ctrl + D and hit enter and it will drop you out of the loop)
#3
Reputation: 1736
- Posts: 5,138
- Joined: 05-May 12
Re: Problem with reading character 'X' from array
Posted Yesterday, 09:42 PM
It's not the root cause of your problem, but you do have a problem of overrunning your array in the loop on lines 50-52.
#4
Reputation: 1736
- Posts: 5,138
- Joined: 05-May 12
Re: Problem with reading character 'X' from array
Posted Yesterday, 09:49 PM
And your algorithm for checking the check digit seems to be missing the multiplication of each digit as described in Wikipedia: http://en.wikipedia....git_calculation#5
Reputation: 0
- Posts: 7
- Joined: 02-April 13
Re: Problem with reading character 'X' from array
Posted Yesterday, 09:59 PM
Skydiver, on 05 April 2013 - 09:49 PM, said:
Yeah I am using an algorithm my teacher has given me, and it works for all of the ISBN's he has given me except for the ones with X's at the end. a couple of the ones he has given me are 0-89237-010-6 0-8306-3637-4, my algorithm is fine from what I have checked, I am just having problems with ISBN's with X's at the end#6
Reputation: 123
- Posts: 1,279
- Joined: 13-June 08
Re: Problem with reading character 'X' from array
Posted 3 minutes ago
I'm making a guess, but based on what I'm seeing, this is your problem.(isbn[i][k] >= '0' && isbn[i][k] <= '9') || (save == 10 && isbn[i][k] == 'X')
Problem is, when does save = 10? The only time I see you setting Save is if it passes this if statement and has an 'X'. And you have an And statement so..
save == 10 AND isbn[i][k] == 'X'
Except, Save will never equal 10...unless it passes this if check and gets down to the primary if isbn == x. But it won't, again, because save is never 10 at the same time the isbn is X and since X is greater than 0 but also greater than 9, it just passes the giant if statement when it hits an X and hits the elseif.
This post has been edited by ccubed: A minute ago
Page 1 of 1
Source: http://www.dreamincode.net/forums/topic/317778-problem-with-reading-character-x-from-array/
tony stewart kurt busch kurt busch nba dunk contest 2012 act of valor woody guthrie benson henderson
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.