473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Error in integer output!

Lewis Mbuthia
I wrote this simple code after introducing myself to the gematria pattern in the Hebrew language.
The program is supposed to input Hebrew phrases and return the integer values of each character.
It compiles great but the output has a series of integers, namely the number 40 at the end of the output process, which has no corresponding character input.
Can anyone suggest a way to remove this error since the output MAY be included in further processes.Any help is highly appreciated.
Here's the code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. # include <iostream>
  3. # include <string.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int g1=1000,g2=0,dec=0;
  9.     string heb;
  10.     cout<< "This is the hebrew letter scheme \t";
  11.     cout<< "A-Alef \t";
  12.     cout<< "B-Beth \t";
  13.     cout<< "G-Gyml \t";
  14.     cout<< "D-Dalet \t";
  15.     cout<< "H-He \t";
  16.     cout<< "V-Vau \t";
  17.     cout<< "Z-Zain \t";
  18.     cout<< "C-Chet \t";
  19.     cout<< "T-Teth \t";
  20.     cout<< "Y-Yod \t";
  21.     cout<< "K-Kaf \t";
  22.     cout<< "L-Lamed \t";
  23.     cout<< "M-Mem \t";
  24.     cout<< "N-Nun \t";
  25.     cout<< "S-Samek \t";
  26.     cout<< "I-Ain \t";
  27.     cout<< "P-Pey \t";
  28.     cout<< "O-Tsadhe \t";
  29.     cout<< "Q-Qof \t";
  30.     cout<< "R-Resh \t";
  31.     cout<< "E-Shin \t";
  32.     cout<< "F-Tav \t";
  33.     cout<< "k-final Kaf\t";
  34.     cout<< "m-final Mem\t";
  35.     cout<< "n-final Nun\t";
  36.     cout<< "p-final Pey\t";
  37.     cout<< "o-final Tsadhe\t";
  38.     cout<< "Input Hebrew phrase->\t";
  39.  
  40.     getline(cin,heb);
  41.  
  42.     cout<< "These are the results-> \n";
  43.  
  44.     while (g2<=g1)
  45.     {
  46.       switch (heb[g2])
  47.       {    
  48.        case 'A':
  49.        dec=1000; 
  50.        break;
  51.        case 'B': 
  52.        dec=2; 
  53.        break;
  54.        case 'G':
  55.        dec=3; 
  56.        break;
  57.        case 'D':
  58.        dec=4; 
  59.        break;
  60.        case 'H':
  61.        dec=5; 
  62.        break;
  63.        case 'V':
  64.        dec=6; 
  65.        break;
  66.        case 'Z':
  67.        dec=7; 
  68.        break;
  69.        case 'C':
  70.        dec=8; 
  71.        break;
  72.        case 'T':
  73.        dec=9; 
  74.        break;
  75.        case 'Y':
  76.        dec=10; 
  77.        break;
  78.        case 'K':
  79.        dec=20; 
  80.        break;
  81.        case 'L':
  82.        dec=30; 
  83.        break;
  84.        case 'M':
  85.        dec=40; 
  86.        break;
  87.        case 'N':
  88.        dec=50; 
  89.        break;
  90.        case 'S':
  91.        dec=60; 
  92.        break;
  93.        case 'I':
  94.        dec=70; 
  95.        break;
  96.        case 'P':
  97.        dec=80; 
  98.        break;
  99.        case 'O':
  100.        dec=90; 
  101.        break;
  102.        case 'Q':
  103.        dec=100; 
  104.        break;
  105.        case 'R':
  106.        dec=200; 
  107.        break;
  108.        case 'E':
  109.        dec=300; 
  110.        break;
  111.        case 'F':
  112.        dec=400; 
  113.        break;
  114.        case 'k':
  115.        dec=500; 
  116.        break;
  117.        case 'm':
  118.        dec=600; 
  119.        break;
  120.        case 'n':
  121.        dec=700; 
  122.        break;
  123.        case 'p':
  124.        dec=800; 
  125.        break;
  126.        case 'o':
  127.        dec=900; 
  128.        break;
  129.        default: 
  130.        dec=0;
  131.        break;         
  132.       }
  133.      g2++;
  134.  
  135.        if (dec>=1)
  136.  
  137.         {
  138.          cout << dec << endl;
  139.         }
  140.  
  141.     }
  142.    system("PAUSE");
  143. }
  144.  
  145.  
  146.  
Aug 31 '11 #1

✓ answered by mac11

What is the reasoning behind that loop condition? (g2 <= g1) -- Are you sure you need to loop 1000 times? Maybe run your loop based on the size of the input string.

Also, you should change your #include <string.h> to #include <string>

3 1574
mac11
256 100+
What is the reasoning behind that loop condition? (g2 <= g1) -- Are you sure you need to loop 1000 times? Maybe run your loop based on the size of the input string.

Also, you should change your #include <string.h> to #include <string>
Sep 1 '11 #2
donbock
2,426 Expert 2GB
I think mac11 has given you the clue to the spurious numbers at the end of your output.

That's quite a switch statement! Personally, I would have constructed a big lookup table to keep the executable code small. For example, here's the lookup table:
Expand|Select|Wrap|Line Numbers
  1. struct gematria {
  2.    int c;
  3.    int value;
  4.    char *name;
  5.    }
  6.  
  7. gematria table[] = {
  8.    { 'A', 1000, "Alef" },
  9.    ...
  10.    { 'o',  900, "final Tsadhe" }
  11. };
This table eliminates the long list of cout's to print the index and it eliminates the big switch. I prefer lookup tables because they let me keep related information close together, such as the three pieces of information: 'A' is Aleph and has a value of 1000.
Sep 1 '11 #3
Thanks guyz I rewrote the code and the error is gone.
Sep 2 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: micha | last post by:
whenever an error occurs after ob_start() the buffer is flushed and the content printed. 1. is that standard behaviour? 2. if yes, how to prevent it? micha p.s. i can't use my own error...
3
by: Joseph A Romeo | last post by:
I have written an XSLT transformation on an ASP.NET page. The resulting HTML is primarily a table of links. I have found that when the resulting HTML is less than or equal to 16040 bytes, the...
2
by: silly | last post by:
/*Thanks again to thos who helped with my 'more hand written integer pow() functions (LONG POST)' query. I needed to write a function to write out integers and after looking at some stuff on...
2
by: Siji | last post by:
Hi, I am currently developing a model (numerical computation) for a project. I have this problem with some of the results I get from the output. The output sometimes display this value -1.#IND for...
0
by: ravescar | last post by:
I am currently working on an generic error collection mechanism in ASP.NET2.0 written using C# that can catch unhandled exception on a web application in application level. it automatically save an...
2
by: hph | last post by:
A bunch of small things are frustrating me in trying to do some simple stuff with MySQL and php. For example, I have am trying to sum the data in a particular field, then output the result. ...
3
by: divc | last post by:
I'm writing a simple program to write to files. I'm using pointer to a structure in my program. I've given the code here : #include <stdio.h> #include <string.h> #include <stdlib.h> struct...
3
by: dmitrey | last post by:
hi all, I need printing the following: 1 2 3 .... 9 10 ....
1
by: barmatt80 | last post by:
I have found alot of help on this site, and is helping me along. I am having trouble with a stored procedure. This is my first stored procedure. The task I was given was to create a stored...
3
by: zelmila19 | last post by:
Hi, Can someone tell me what's wrong with my code cos when I test the program, it always gives me the fee as 20 for everything...... #include <iostream> using std::cout; using std::cin;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.