Program will not output correctly

My assignment was to write a program that will take in an ISBN number with dashes and check to see if it is a valid ISBN. The program is meant to stop when the user inputs all zeroes. The issue I am having is that regardless if the ISBN is valid or not it will say the ISBN is Valid.

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
89
90
91
92
93
94
95
96
97
98
99
 #include <iostream>
using namespace std;

int main()
{
 
  char isbn;//Holds user's ISBN number
  string repeat; //Used to enter the first loop
      
  cout << "Would you like to check if an ISBN number is valid or not?"<< endl;
  cout <<"Enter Y for yes or 0000000000 for no: ";
  cin >> repeat;
  
  while (repeat != "0000000000")
  {
      
  	int counter;
  	int limit = 13; //10 isbn numbers and 3 dashes
  	int x = 10; //Initilized incase user inputs x
  	int weightedSum = 0;
  	int code = 0;
  	int weightedValue = 0;
  	int weight = 10;
  	int verification; //Used to hold value of weighted sum modulus 11 for isbn verification
  	
      cout<< "Please enter the ISBN number: ";
      	  
        for (counter = 0; counter < limit; counter++)
  		{
  		
            cin>> isbn;  
            
  			if(isbn >= '0' && isbn <= '9' || isbn == 'x' || isbn== 'X')
	  		switch(isbn)
             {
            
             case '0':
    		 code = 0;
    		 	  break;   
  	         case '1':
             code = 1;
                  break;
             case '2':
             code = 2;
                  break;
             case '3':
             code = 3;
                  break;
             case '4':
             code = 4;
                  break;
             case '5':
             code = 5;
                  break;
             case '6':
             code = 6;
                  break;
             case '7':
             code = 7;
                  break;
             case '8':
             code = 8;
                  break;
             case '9':
             code = 9;
                  break;
             case 'x':
             code = 10;
                  break;
             case 'X':
             code = 10;
                  break;
              default:
                     cout<<"Done validating"<<endl;
                     
            weightedValue = code * weight;  //Caluclates weighted value
            weightedSum = weightedSum + weightedValue; //Calculates weighted sum
            weight--; 
                             
           } 
          
  		}
  		
          verification = weightedSum % 11;
         
           if(verification != 0)
             cout<<"Inalid."<<endl;
           else
             cout<<"valid"<<endl;
             
          cout<<"If you would like to verify another ISBN number input Y, if not enter"<<"\n"<< "0000000000 to stop: ";//User input in order to verify another ISBN number
          cin>>repeat;     
                
  }                                                   
 
     system ("pause");
     return 0; 
} // End of main function
Last edited on
Topic archived. No new replies allowed.