Thread: Switch/case Problems (long code in post)

  1. #1
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094

    Switch/case Problems (long code in post)

    I have looked it up, and I believe I have the right syntax for my switch/case statement. The problem is that it tells me that case 2 is not part of a switch statement.

    Quote Originally Posted by Dev-C++
    c:\docume~1\wraithan\desktop\todesr~1.cpp: In function `int main()':
    c:\docume~1\wraithan\desktop\todesr~1.cpp:293: case label `2' not within a switch statement
    c:\docume~1\wraithan\desktop\todesr~1.cpp:293: confused by earlier errors, bailing out

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    inline void combo1(int& first, int& second)
    {
        while (first>=3)
        {
        first-=3;
        second++;
        }
    }
    
    inline void combo2(int& first, int& second)
    {
        while (first>=2)
        {
        first-=2;
        second++;
        }
    }
    
    inline void cube(int& el, int& eld, int& tir, int& nef, int& eth, int& ith, int& tal, int& ral, int& ort, int& thul, int& amn,
                     int& sol, int& shael, int& dol, int& hel, int& io, int& lum, int& ko, int& fal, int& lem, int& pul, int& um,
                     int& mal, int& ist, int& gul, int& vex, int& ohm, int& lo, int& sur, int& ber, int& jah, int& cham, int& zod)
    {
        combo1(el,eld);
        combo1(eld,tir);
        combo1(tir,nef);
        combo1(nef,eth);
        combo1(eth,ith);
        combo1(ith,tal);
        combo1(tal,ral);
        combo1(ral,ort);
        combo1(ort,thul);
        combo1(thul,amn);
        combo1(amn,sol);
        combo1(sol,shael);
        combo1(shael,dol);
        combo1(dol,hel);
        combo1(hel,io);
        combo1(io,lum);
        combo1(lum,ko);
        combo1(ko,fal);
        combo1(fal,lem);
        combo1(lem,pul);
        combo2(pul,um);
        combo2(um,mal);
        combo2(mal,ist);
        combo2(ist,gul);
        combo2(gul,vex);
        combo2(vex,ohm);
        combo2(ohm,lo);
        combo2(lo,sur);
        combo2(sur,ber);
        combo2(ber,jah);
        combo2(jah,cham);
        combo2(cham,zod);
    }
    
    inline int output(int& el, int& eld, int& tir, int& nef, int& eth, int& ith, int& tal, int& ral, int& ort, int& thul, int& amn,
                       int& sol, int& shael, int& dol, int& hel, int& io, int& lum, int& ko, int& fal, int& lem, int& pul, int& um,
                       int& mal, int& ist, int& gul, int& vex, int& ohm, int& lo, int& sur, int& ber, int& jah, int& cham, int& zod)
    {
        cout<< "El:" << el << "      " << "Eld:" << eld << endl << "Tir:" << tir << "     "
        << "Nef:" << nef  << endl << "Eth:" << eth << "     " << "Ith:" << ith
        << endl << "Tal:" << tal << "     " << "Ral:" << ral << endl << "Ort:" << ort
        << "     " << "Thul:" << thul << endl << "Amn:" << amn << "     " << "Sol:"
        << sol << endl << "Shael:" << shael << "   " << "Dol:" << dol << endl << "Hel:"
        << hel << "     " << "Io:" << io << endl << "Lum:" << lum << "     " << "Ko:"
        << ko << endl << "Fal:" << fal << "     " << "Lem:" << lem << endl << "Pul:"
        << pul << "     " "Um:" << um << endl << "Mal:" << mal << "     " << "Ist:"
        << ist << endl << "Gul:" << gul << "     " << "Vex:" << vex << endl << "Ohm:"
        << ohm << "     " << "Lo:" << lo << endl << "Sur:" << sur << "     " << "Ber:"
        << ber << endl << "Jah:" << jah << "     " << "Cham:" << cham << endl << "Zod:" << zod <<endl;
        return 0;
    }
    
    inline void loadfile(ifstream& file)
    {
        file.open("Runes.txt");
        if (!file.is_open())
            file.open( "runes.txt");
            if (!file.is_open())
                file.open( "rune.txt");
                if (!file.is_open())
                    file.open( "Rune.txt");
                    if (!file.is_open())
                        {
                        string filename;
                        cout<<"TodesRunes could not find your ATMA dump,"<<endl<<"please specify the path to the txt file."<<endl;
                        getline(cin,filename);
                        cout<<endl<<"Parsing:"<<filename<<endl;
                        file.open(filename.c_str());
                        }
                        if (!file.is_open())
                            cout<<"The file does not appear to be here!";
    }
    
    inline void counter(int& el, int& eld, int& tir, int& nef, int& eth, int& ith, int& tal, int& ral, int& ort, int& thul, int& amn,
                        int& sol, int& shael, int& dol, int& hel, int& io, int& lum, int& ko, int& fal, int& lem, int& pul, int& um,
                        int& mal, int& ist, int& gul, int& vex, int& ohm, int& lo, int& sur, int& ber, int& jah, int& cham, int& zod, ifstream& file)
    {
            string line;
            while (getline( file , line ))
    	    {
                if (line.empty() || (line == "\r")) continue;
                int colon_pos = line.find(':');
                string rune = line.substr(colon_pos+2,line.size()-colon_pos-7);
                if (rune == "El")
                    el++;
                else if (rune == "Eld")
                    eld++;
                else if (rune == "Tir")
                    tir++;
                else if (rune == "Nef")
                    nef++;
                else if (rune == "Eth")
                    eth++;
                else if (rune == "Ith")
                    ith++;
                else if (rune == "Tal")
                    tal++;
                else if (rune == "Ral")
                    ral++;
                else if (rune == "Ort")
                    ort++;
                else if (rune == "Thul")
                    thul++;
                else if (rune == "Amn")
                    amn++;
                else if (rune == "Sol")
                    sol++;
                else if (rune == "Shael")
                    shael++;
                else if (rune == "Dol")
                    dol++;
                else if (rune == "Hel")
                    hel++;
                else if (rune == "Io")
                    io++;
                else if (rune == "Lum")
                    lum++;
                else if (rune == "Ko")
                    ko++;
                else if (rune == "Fal")
                    fal++;
                else if (rune == "Lem")
                    lem++;
                else if (rune == "Pul")
                    pul++;
                else if (rune == "Um")
                    um++;
                else if (rune == "Mal")
                    mal++;
                else if (rune == "Ist")
                    ist++;
                else if (rune == "Gul")
                    gul++;
                else if (rune == "Vex")
                    vex++;
                else if (rune == "Ohm")
                    ohm++;
                else if (rune == "Lo")
                    lo++;
                else if (rune == "Sur")
                    sur++;
                else if (rune == "Ber")
                    ber++;
                else if (rune == "Jah")
                    jah++;
                else if (rune == "Cham")
                    cham++;
                else if (rune == "Zod")
                    zod++;
        	}
    }
    
    inline void SaveNoCube(ofstream& save,int& el, int& eld, int& tir, int& nef, int& eth, int& ith, int& tal, int& ral, int& ort, int& thul, int& amn,
                        int& sol, int& shael, int& dol, int& hel, int& io, int& lum, int& ko, int& fal, int& lem, int& pul, int& um,
                        int& mal, int& ist, int& gul, int& vex, int& ohm, int& lo, int& sur, int& ber, int& jah, int& cham, int& zod)
    {
    
        string filename;
        cout<<"Specify path if you had to when loading."<<endl<<"Save name:"<<endl;
        getline(cin,filename);
        save.open(filename.c_str());
        if (!save.is_open())
            cout<<"The file does not appear to be here!";
        else
            save<<"Total Runes: "<<el + eld + tir + nef + eth + ith + tal + ral + ort + thul + amn +
                                   sol + shael + dol + hel + io + lum + ko + fal + lem + pul + um +
                                   mal + ist + gul + vex + ohm + lo + sur + ber + jah + cham + zod <<endl;
            save<<output(el, eld, tir, nef, eth, ith, tal, ral, ort, thul, amn,
                         sol, shael, dol, hel, io, lum, ko, fal, lem, pul, um,
                         mal, ist, gul, vex, ohm, lo, sur, ber, jah, cham, zod);
    /*        save<<output(el2, eld2, tir2, nef2, eth2, ith2, tal2, ral2, ort2, thul2, amn2,
                             sol2, shael2, dol2, hel2, io2, lum2, ko2, fal2, lem2, pul2, um2,
                             mal2, ist2, gul2, vex2, ohm2, lo2, sur2, ber2, jah2, cham2, zod2);
    */
    }
    
    inline void swap(int& el, int& eld, int& tir, int& nef, int& eth, int& ith, int& tal, int& ral, int& ort, int& thul, int& amn,
                     int& sol, int& shael, int& dol, int& hel, int& io, int& lum, int& ko, int& fal, int& lem, int& pul, int& um,
                     int& mal, int& ist, int& gul, int& vex, int& ohm, int& lo, int& sur, int& ber, int& jah, int& cham, int& zod,
                     int& el2, int& eld2, int& tir2, int& nef2, int& eth2, int& ith2, int& tal2, int& ral2, int& ort2, int& thul2, int& amn2,
                     int& sol2, int& shael2, int& dol2, int& hel2, int& io2, int& lum2, int& ko2, int& fal2, int& lem2, int& pul2, int& um2,
                     int& mal2, int& ist2, int& gul2, int& vex2, int& ohm2, int& lo2, int& sur2, int& ber2, int& jah2, int& cham2, int& zod2)
    {
        el2 = el;
        eld2 = eld;
        tir2 = tir;
        nef2 = nef;
        eth2 = eth;
        ith2 = ith;
        tal2 = tal;
        ral2 = ral;
        ort2 = ort;
        thul2 = thul;
        amn2 = amn;
        sol2 = sol;
        shael2 = shael;
        dol2 = dol;
        hel2 = hel;
        io2 = io;
        lum2 = lum;
        ko2 = ko;
        fal2 = fal;
        lem2 = lem;
        pul2 = pul;
        um2 = um;
        mal2 = mal;
        ist2 = ist;
        gul2 = gul;
        vex2 = vex;
        ohm2 = ohm;
        lo2 = lo;
        sur2 = lo;
        ber2 = ber;
        jah2 = jah;
        cham2 = cham;
        zod2 = zod;
    }
    
    
    int main ()
    {
        cout<<"Welcome to TodesRunes 1.0!"<<endl;
        int run = 1;
        int cubed = 0;
        int el = 0, eld = 0, tir = 0, nef = 0, eth = 0, ith = 0, tal = 0, ral = 0, ort = 0, thul = 0,amn = 0,
            sol = 0, shael = 0, dol = 0, hel = 0, io = 0, lum = 0, ko = 0, fal = 0, lem = 0,pul = 0, um = 0,
            mal = 0, ist = 0, gul = 0, vex = 0, ohm = 0, lo = 0, sur = 0, ber = 0, jah = 0, cham = 0, zod = 0;
        int el2 = 0, eld2 = 0, tir2 = 0, nef2 = 0, eth2 = 0, ith2 = 0, tal2 = 0, ral2 = 0, ort2 = 0, thul2 = 0,amn2 = 0,
            sol2 = 0, shael2 = 0, dol2 = 0, hel2 = 0, io2 = 0, lum2 = 0, ko2 = 0, fal2 = 0, lem2 = 0,pul2 = 0, um2 = 0,
            mal2 = 0, ist2 = 0, gul2 = 0, vex2 = 0, ohm2 = 0, lo2 = 0, sur2 = 0, ber2 = 0, jah2 = 0, cham2 = 0, zod2 = 0;
    
        ifstream file;
    
        counter(el, eld, tir, nef, eth, ith, tal, ral, ort, thul, amn,
                sol, shael, dol, hel, io, lum, ko, fal, lem, pul, um,
                mal, ist, gul, vex, ohm, lo, sur, ber, jah, cham, zod, file);
    
        loadfile(file);
    
        cout<< "There are "<<el + eld + tir + nef + eth + ith + tal + ral + ort + thul + amn +
               sol + shael + dol + hel + io + lum + ko + fal + lem + pul + um +
               mal + ist + gul + vex + ohm + lo + sur + ber + jah + cham + zod <<" runes that have been sorted" << endl;
    
        while(run!=4)
        {
            cout<<"1. Cube all runes to the max."<<endl<<"2. Display current runes."<<
            endl<<"3. Save data to a file."<<endl<<"4. Blame Durf!!!! (quit)"<<endl<<"Choice: ";
            cin>>run;
            switch(run)
                case 1:
                    swap(el, eld, tir, nef, eth, ith, tal, ral, ort, thul, amn,
                         sol, shael, dol, hel, io, lum, ko, fal, lem, pul, um,
                         mal, ist, gul, vex, ohm, lo, sur, ber, jah, cham, zod,
                         el2, eld2, tir2, nef2, eth2, ith2, tal2, ral2, ort2, thul2, amn2,
                         sol2, shael2, dol2, hel2, io2, lum2, ko2, fal2, lem2, pul2, um2,
                         mal2, ist2, gul2, vex2, ohm2, lo2, sur2, ber2, jah2, cham2, zod2);
                    cube(el2, eld2, tir2, nef2, eth2, ith2, tal2, ral2, ort2, thul2, amn2,
                         sol2, shael2, dol2, hel2, io2, lum2, ko2, fal2, lem2, pul2, um2,
                         mal2, ist2, gul2, vex2, ohm2, lo2, sur2, ber2, jah2, cham2, zod2);
                    cubed = 1;
                    output(el2, eld2, tir2, nef2, eth2, ith2, tal2, ral2, ort2, thul2, amn2,
                         sol2, shael2, dol2, hel2, io2, lum2, ko2, fal2, lem2, pul2, um2,
                         mal2, ist2, gul2, vex2, ohm2, lo2, sur2, ber2, jah2, cham2, zod2);
                    break;
                case 2:
                    output(el, eld, tir, nef, eth, ith, tal, ral, ort, thul, amn,
                           sol, shael, dol, hel, io, lum, ko, fal, lem, pul, um,
                           mal, ist, gul, vex, ohm, lo, sur, ber, jah, cham, zod);
                    break;
                case 3:
                    ofstream save;
                    SaveNoCube(save, el, eld, tir, nef, eth, ith, tal, ral, ort, thul, amn,
                         sol, shael, dol, hel, io, lum, ko, fal, lem, pul, um,
                         mal, ist, gul, vex, ohm, lo, sur, ber, jah, cham, zod);
                    break;
                case 4:
                    return 0;
                    break;
                default:
                    cout<<"You entered an invalid response, please try agian"<<endl;
                    break;
        }
    	cin.get();
    }

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    you need to enclose your case statments in braces

    Code:
    switch (var)
    {
         case 1:
         break;
    
         case 2:
         break;
    
         case default:
         break;
    }

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I knew it had to be somehting simple, thank you. If anyone is curious what this is (since a lot of people play D2 and reconize the runes) http://forums.diabloii.net/forumdisplay.php?f=3 look for the post that says TodesRunes - A parser for your rune stash.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bad code in book?
    By Darklighter in forum C++ Programming
    Replies: 7
    Last Post: 09-30-2006, 11:57 AM
  2. Merge and Heap..which is really faster
    By silicon in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2005, 04:06 PM
  3. Insertion Sort Problem
    By silicon in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2005, 12:30 PM
  4. Replies: 12
    Last Post: 02-20-2005, 08:48 AM
  5. problems with output from code
    By simhap in forum C++ Programming
    Replies: 0
    Last Post: 10-08-2001, 12:43 PM