GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Nov-2007, 18:56
slapshot6819 slapshot6819 is offline
New Member
 
Join Date: Nov 2007
Posts: 5
slapshot6819 is on a distinguished road

An easy problem solve for most of you


My program is supposed to add/subtract roman numerals, but order does not matter. (aka, xi = 11 and ix = 11. makes it a lot easier, anyway though...) It is not finished as of yet, but something causes it to crash unmercifully even though it compiles just fine. I've looked at my code for a while and can't figure out what I did wrong; if you could take a look and point me in the right direction that would be great! Thank you very much.


CPP / C++ / C Code:
#include <iostream>
#include <string>

using namespace std;

void rtod(char expession[], int &roman1, int &roman2, char &opperator);

int main()
{
    char expression[25] = "                        ";
    char opperator;
    int roman1, roman2;

    cout << "Welcome to my roman numeral calculator!!" << endl;
    cout << "********************************************\nTo use the calculator..." << endl;
    cout << "Simply enter the first number followed by the opperator followed by the other opperator!" << endl;
    cout << "Notes: order of letters does not matter! Enter 0 to exit. Case does not matter." << endl;
    cout << "Addition: +\tSubtraction: -\tMultiplication: *" << endl;
    cout << endl;

    while(expression[0] != '0')
    {
        cout << "Ready for input..." << endl;
        cin >> expression;

        rtod(expression, roman1, roman2, opperator);

        cout << endl;
        cout << roman1 << " " << roman2 << endl;

    }

    
    return 0;
}

void rtod(char expression[], int &roman1, int &roman2, char &opperator)
{
    int counter = 0;
    roman1 = 0;
    roman2 = 0;

    while(expression[counter] != '*' || expression[counter] != '+' || expression[counter] != '-')
    {
        switch(expression[counter])
        {
            case 'I':
            case 'i':
                roman1 = roman1 + 1;
            case 'V':
            case 'v':
                roman1 = roman1 + 5;
            case 'X':
            case 'x':
                roman1 = roman1 + 10;
            case 'L':
            case 'l':
                roman1 = roman1 + 50;
            case 'C':
            case 'c':
                roman1 = roman1 + 100;
            case 'D':
            case 'd':
                roman1 = roman1 + 500;
            case 'M':
            case 'm':
                roman1 = roman1 + 1000;
        }

        counter++;
    }

    opperator = expression[counter];

    while(expression[counter] != '\0')
    {
        switch(expression[counter])
        {
            case 'I':
            case 'i':
                roman2 = roman2 + 1;
            case 'V':
            case 'v':
                roman2 = roman2 + 5;
            case 'X':
            case 'x':
                roman2 = roman2 + 10;
            case 'L':
            case 'l':
                roman2 = roman2 + 50;
            case 'C':
            case 'c':
                roman2 = roman2 + 100;
            case 'D':
            case 'd':
                roman2 = roman2 + 500;
            case 'M':
            case 'm':
                roman2 = roman2 + 1000;
        }

        counter++;
    }
}

EDIT: sorry, i have it spaced neatly in the compiler, but clearly, not here
Last edited by admin II : 20-Nov-2007 at 08:01. Reason: Please surround your C++ code with [cpp] your code [/cpp]
  #2  
Old 19-Nov-2007, 19:12
slapshot6819 slapshot6819 is offline
New Member
 
Join Date: Nov 2007
Posts: 5
slapshot6819 is on a distinguished road

Re: An easy problem solve for most of you


Nevermind! I found it. those || have to be &&. other wise a single character has to be all 3 of those other characters at once, which makes no sense at all
  #3  
Old 20-Nov-2007, 03:14
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: An easy problem solve for most of you


Quote:
Originally Posted by slapshot6819
EDIT: sorry, i have it spaced neatly in the compiler, but clearly, not here
Clearly if you read the Guidelines, your code would look better.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Description: Graph’s Degree.....can help me to solve this out? thefinalyy C++ Forum 0 24-Aug-2007 06:42
Problem with using classes as Parameters and Return Types wmbest2 C++ Forum 3 13-Mar-2007 21:08
Hitting a logic problem I can't solve Elsydeon C++ Forum 3 09-Oct-2005 22:29
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 08:03
Please help to solve me a problem with multiline texrbox and checkbox mithila MS Visual C++ / MFC Forum 0 08-Sep-2004 23:08

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:07.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.