college needs help again...ya diggg

This is a discussion on college needs help again...ya diggg within the C++ Programming forums, part of the General Programming Boards category; Does anyone see whats wrong with the code Hey im back everyone Really need some help or rather some hints ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    college needs help again...ya diggg

    Does anyone see whats wrong with the code

    Hey im back everyone
    Really need some help or rather some hints
    Last time i was stressing over something that was very simple .

    Everyone on the site seems so nice and im loving it.

    Need help ...i need help please pretty please



    Code:
    
    #include<iostream>
    using namespace std;
    
    int main(void)
    {
        system("TITLE Calculator")
    
        char cChar;
        double dfirstnumber;
        double dsecondnumber;
        char cDoagain;
        
    do
    (
        system("CLS");
        cout <<"please enter the first number you would like to use"
            << endl;
        cin >> dfirstnumber;
        cout << " please enter the operation that you would liek to complete"
          << " (+,-,* or /)" << endl;
        cin >> cChar;
        
        cout << " please enter the second number you would like to use"
            << endl;
            
        switch (cChar)
        (
        case "+":
            cout << " The answer is " << dfirstnumber << " + " <<
                    dsecondnumber << " * " << (dfirstnumber + dsecondnumber) << endl;
            break;        
        case "-"
            cout << " The answer is " << dfirstnumber <<  "-" <<
                    dsecondnumber << " * " << (dfirstnumber - dsecondnumber) << endl;
             break;       
        case "*":
            cout << " The answer is " << dfirstnumber << " * " <<
                    dsecondnumber << " * " << (dfirstnumber * dsecondnumber) << endl;
            break;
        case "x":
            cout << " The answer is " << dfirstnumber << " x " <<
                    dsecondnumber << " * " << (dfirstnumber * dsecondnumber) << endl;
            break;        
        case "X":
            cout << " The answer is " << dfirstnumber << " X " <<
                    dsecondnumber << " * " << (dfirstnumber = dsecondnumber) << endl;
             break;
        
        case "/":
            if (dsecondnumber==0)(
                cout << " That is an invalid operation" << endl;
                )else (
            cout << " The answer is " << dfirstnumber << " / " <<
                    dsecondnumber << " * " << (dfirstnumber / dsecondnumber) <, endl;
                    )
                    break ;
                    
        default:
           cout << " That is an invalid operation" << endl;
           break;
           (
           
           cout << " Would you like to statr again ? ( y or n ) "
           << endl
           cin >> cDoagain;
           )while( cDoagain == " Y " || cdoagain ==  "y");
           system (" PAUSE")
           return 0;
           }
    Last edited by joemelle; 08-27-2007 at 09:05 PM. Reason: left a the question out

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    despite you editing, I don't see a question anywhere. at least not a specific one.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    There is A LOT wrong in that entire code, look through it again very carefully.

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    7

    There's one simple problem that I saw right away

    With a switch statement, you can only use integers, not characters. So, for the operators, try giving them a number value, having your users type that number to perform the operation, and then keep using that number. Or, another thing you could do is use if...then...else statements. I only took a quick glance at it though, so there may be other things wrong with your code, but that should help (I remember making the same mistake doing the same thing, so I recognized it easily).

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    7
    Another quick fix

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    You can use a char with a switch statement, then just have to be enclosed in ' ' and not " "like
    Code:
    case 'a':
    break;
    
    case 'b':
    break;
    Last edited by scwizzo; 08-27-2007 at 09:55 PM.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    7
    You can? Sorry then, perhaps I didn't single quote it then... lol, I don't remember, but anyway, to explain the "Another quick fix" post, that was supposed to be the beginning of an edit to my even earlier post, with some more help, but my computer started lagging and everything screwed up.

  8. #8
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Ok im just gonna make a quick list of things i noticed. (my computer messed up too so i couldnt finish my edit of the other post)

    1. using () where there should be
    Code:
    {}
    2. using " " where there should be ' '
    3. missing ; in a couple places
    4. missing cin>> for the dsecondnumber variable
    5. poor indentation

  9. #9
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    thanks

    thanks everyone i will keep fixing them......doing it right now

  10. #10
    Registered User
    Join Date
    Oct 2006
    Location
    London
    Posts
    14
    Code:
    int main(void)
    should be :
    Code:
    int main()

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    No. In C++, both methods are exactly equivalent. In C, it's different, but this is the C++ programming forum.

    Actually, it should be
    Code:
    int main(int argc, char *argv[])
    but let's not get picky.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    int main() and int main(void) are both better than int main(int argc, char *argv[]) in this case. All are legal and standard, but the first two indicate that no command line arguments are being used.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Perhaps I should post the contents of a PM replying to laserlight.
    Quote Originally Posted by dwks
    Quote Originally Posted by laserlight
    Quote Originally Posted by dwks View Post
    Actually, it should be
    Code:
    int main(int argc, char *argv[])
    but let's not get picky.
    What is your reasoning for saying that command line parameters should be included even when the command line arguments are not used?

    Regards,
    laserlight
    In C, int main() is preferred over int main(void), because the latter means that main takes no parameters, and the code generated for it sometimes assumes this; so when argc and argv are passed to the program by the operating system, the stack can get corrupted.

    Or so I hear. Someone else (matsp, I think) explains it better than I.

    Anyway, in C++, since int main() and int main(void) are exactly the same -- that is, zero parameters, not unknown parameters -- I thought that the same mechanism might be generated, assuming that no parameters were passed to main(). I don't actually have any proof for this line of reasoning, however.

    Another way of putting it: I think the int main() C-style function declarations (with an unknown number of parameters) were dropped from C++ along with function prototypes, like this.
    Code:
    int fputc();
    So it would seem that int main() became equivalent to int main(void), and since int main(void) is not completely proper, one shouldn't use either in C++.

    Any feedback on this would be appreciated.
    I guess if int main(void) is okay then int main() is okay too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    I have never heard of that before, but I seriously doubt it is an issue any more. Also, since int main() is standard C++, you can safely use it on any standards conforming compiler.

  15. #15
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You're also missing the header file for system() (even though VC++ automagically includes certain headers for you).

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. College residence - Campus or commute?
    By holden in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-17-2004, 03:54 AM
  2. Should I go to a state college and be 20k in debt, or a private college and be 90k in
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-10-2003, 08:22 PM
  3. University versus college, which should I do?
    By Terrance11 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-02-2003, 11:19 PM
  4. Which college should I go to?
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 05-13-2003, 10:06 PM
  5. College or No College :: Future
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 09-25-2002, 03:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21