রবিবার, ৭ এপ্রিল, ২০১৩

Problem With Reading Character 'X' From Array - C And C++ ...


Example
#{example}
"); ipb.editor_values.get('templates')['togglesource'] = new Template("
??? Cancel Source Edit
"); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
  • Icon
  • "); ipb.editor_values.get('templates')['menu_item'] = new Template("
  • #{title}
  • "); ipb.editor_values.get('templates')['togglesource'] = new Template("
    ??? Cancel Source Edit
    "); ipb.editor_values.get('templates')['emoticons_showall'] = new Template(""); ipb.editor_values.get('templates')['emoticon_wrapper'] = 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]\n \n Test\n \n[/xml]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"member":{"id":"31","title":"Member","desc":"Given a member name, a link is automatically generated to the member's profile","tag":"member","useoption":"1","example":"[member=skyhawk133] runs this site.","switch_option":"0","menu_option_text":"Input Username of Member","menu_content_text":"","single_tag":"1","optional_option":"0","image":"memberbbcode.png"},"extract":{"id":"33","title":"Extract Blog Entry","desc":"This will allow users to define an extract for an entry. Only this piece of the entry will be displayed on the main blog page and will show up in the RSS feed.","tag":"extract","useoption":"0","example":"[extract]This is an example![/extract]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"blog":{"id":"34","title":"Blog Link","desc":"This tag provides an easy way to link to a blog.","tag":"blog","useoption":"1","example":"[blog=100]Click me![/blog]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"entry":{"id":"35","title":"Blog Entry Link","desc":"This tag provides an easy way to link to a blog entry.","tag":"entry","useoption":"1","example":"[entry=100]Click me![/entry]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"twitter":{"id":"36","title":"Twitter","desc":"A tag to link to a user's twitter account","tag":"twitter","useoption":"0","example":"[twitter]userName[/twitter]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"twitter.png"},"inline":{"id":"37","title":"Inline Code","desc":"Formats code inline instead of in a seperate code box. ","tag":"inline","useoption":"0","example":"[inline]style=\"font-size: 12px;\"[/inline]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"il":{"id":"38","title":"Abbreviated Inline (IL)","desc":"Abbreviated version of the [inline] tag. ","tag":"il","useoption":"0","example":"[il]Code Here[/il]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":"il2.png"},"code":{"id":"41","title":"Code","desc":"Allows you to enter general code","tag":"code","useoption":"1","example":"[code]$text = 'Some long code here';[/code]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"1","image":""}}) ); ipb.vars['emoticon_url'] = "http://cdn.dreamincode.net/forums/public/style_emoticons/default"; //Search Setup ipb.vars['search_type'] = 'forum'; ipb.vars['search_type_id'] = 15; ipb.vars['search_type_2'] = 'topic'; ipb.vars['search_type_id_2'] = 317778; //]]>

    5 Replies - 33 Views - Last Post: 3 minutes ago Rate Topic: -----

    #1 babyhands ?Icon User is offline

    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 babyhands ?Icon User is offline

    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 Skydiver ?Icon User is online

    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 Skydiver ?Icon User is online

    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 babyhands ?Icon User is offline

    Reputation: 0

    • Posts: 7
    • Joined: 02-April 13

    Re: Problem with reading character 'X' from array

    Posted Yesterday, 09:59 PM

    View PostSkydiver, 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 ccubed ?Icon User is online

    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/

    tyler clementi kevin kolb sarah shahi rutgers dharun ravi george clooney arrested ravi

    কোন মন্তব্য নেই:

    একটি মন্তব্য পোস্ট করুন