whats wrond with the following C++ code...

Sharky Forums


Results 1 to 11 of 11

Thread: whats wrond with the following C++ code...

  1. #1
    Catfish
    Join Date
    Dec 2001
    Location
    UK
    Posts
    156

    whats wrond with the following C++ code...

    #include<iostream.h>
    int main ()

    {
    int earn;

    cin>>"Enter your wage";
    if (earn<6000);
    cout<<"You dont pay tax"<<endl;
    if ((earn>5000) && (earn<20000));
    cout<<"You have to pay 20%"<<endl;
    if (earn>=20000);
    cout<<"You pay 90%"<<endl;

    }

    i get two errors. whats wrong wid the code
    * Mesh ATX MIDI Tower Case + 300W PSU
    * Athlon DDR 333MHZ Motherboard (Onboard sound)
    * AMD Athlon XP 2200+ CPU (266MHZ)
    * 512MB (2 x 256MB) PC2100 DDR MEMORY (266MHZ)
    * 120GB Ultra Fast (7200rpm) HD with 2mb Buffer
    * 1.44 MB Floppy Disk Drive
    * Teac 40 x 12 x 48 IDE CD-RW
    * 128 MB NVIDIA GFORCE4 TI 4200 + TV out & DVI
    * 19" Hansol Digital Monitor 0.26mm
    * Logitech Navigator Cordless Keyboard & Mouse
    * 16x LG DVD ROM Drive
    * Creative Sound Blaster AUdigy W/SB1394 (Firewire)
    * 56kbs Modem
    * Creavite Labs Inspire 5300 Five Point Surrounds
    * Lexmark X83 Printer (All in one)

  2. #2
    RIP SiS :( CrawlingEye's Avatar
    Join Date
    Dec 2001
    Location
    Easton, Pa, USA
    Posts
    7,441
    What errors?

    I'm not really into programming anymore, but I assume this info would help the programming gurus answer your question.
    -mark

    OC Crusader
    Sigma Dir CrawlingEye of the Cooler's Guild
    SharkyExtreme.com 3D Mark Team


    Samsung SM348
    Asus P4S533
    Pentium 4 2.26b
    Samsung pc2700 512MB
    Seagate Barracuda IV 40gig 7200RPM
    ATi Radeon 9700 Pro
    Audigy 2
    Leadtek WinFast TV 2000 XP
    Antec pp412x
    Cambridge Megaworks THX 550
    Sennheiser HD212 Pro
    Sennheiser mx300
    Ultrasone HFI 650 Trackmaster
    Rio Karma


    3D Mark 2001SE Compare: 14707
    3D Mark 2003 Compare: 4550

  3. #3
    Catfish
    Join Date
    Dec 2001
    Location
    UK
    Posts
    156
    here is the complete list of errors that i got when i tried compiling the program:
    ************************************************************ ********
    Linking...
    calcutaing salary.obj : error LNK2005: _main already defined in book practise.obj

    Debug/Book practise.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.
    * Mesh ATX MIDI Tower Case + 300W PSU
    * Athlon DDR 333MHZ Motherboard (Onboard sound)
    * AMD Athlon XP 2200+ CPU (266MHZ)
    * 512MB (2 x 256MB) PC2100 DDR MEMORY (266MHZ)
    * 120GB Ultra Fast (7200rpm) HD with 2mb Buffer
    * 1.44 MB Floppy Disk Drive
    * Teac 40 x 12 x 48 IDE CD-RW
    * 128 MB NVIDIA GFORCE4 TI 4200 + TV out & DVI
    * 19" Hansol Digital Monitor 0.26mm
    * Logitech Navigator Cordless Keyboard & Mouse
    * 16x LG DVD ROM Drive
    * Creative Sound Blaster AUdigy W/SB1394 (Firewire)
    * 56kbs Modem
    * Creavite Labs Inspire 5300 Five Point Surrounds
    * Lexmark X83 Printer (All in one)

  4. #4
    Hammerhead Shark
    Join Date
    Nov 2000
    Location
    San Diego, CA
    Posts
    1,222
    not suppose to have ";" after the if statement.

  5. #5
    Catfish
    Join Date
    Dec 2001
    Location
    UK
    Posts
    156
    no use, i removed the ";" sign but its of no use, i still get the same errors.
    * Mesh ATX MIDI Tower Case + 300W PSU
    * Athlon DDR 333MHZ Motherboard (Onboard sound)
    * AMD Athlon XP 2200+ CPU (266MHZ)
    * 512MB (2 x 256MB) PC2100 DDR MEMORY (266MHZ)
    * 120GB Ultra Fast (7200rpm) HD with 2mb Buffer
    * 1.44 MB Floppy Disk Drive
    * Teac 40 x 12 x 48 IDE CD-RW
    * 128 MB NVIDIA GFORCE4 TI 4200 + TV out & DVI
    * 19" Hansol Digital Monitor 0.26mm
    * Logitech Navigator Cordless Keyboard & Mouse
    * 16x LG DVD ROM Drive
    * Creative Sound Blaster AUdigy W/SB1394 (Firewire)
    * 56kbs Modem
    * Creavite Labs Inspire 5300 Five Point Surrounds
    * Lexmark X83 Printer (All in one)

  6. #6
    Catfish
    Join Date
    Mar 2002
    Posts
    109
    Well, I believe you have a few errors. First of all, the semicolons on the if statements. Second, the cin operator does not output code. You should have written:

    cout << "Enter your wage: ";
    cin >> wage;

    Also, your main functions is declared as an integer type. Therefore, the function MUST return a value. Try sticking a return 0 statement at the end of your code. That should work.

  7. #7
    Hammerhead Shark punkrawk's Avatar
    Join Date
    Jul 2001
    Location
    sd,ca,usa
    Posts
    1,237
    return 0;

    to be exact.

    anyway, have u tried getting a compiler that tells u what kind of error its getting? i like visual c++ and ive also used codewarrior. that one will tell u if its a delaration syntax error, ; expected before statement, etc. both are quite nice, try out each one, and consider puyrchasing the one u like the most.
    Specs:
    Hercules Prophetview 920 17" LCD of *** kicking
    WIN XP Pro of *** kicking
    P3 733 @ 792
    384 MB Crucial CAS 3 RAM
    Geforce 4 4200 64 MB of *** kicking
    Lite-On 48x12x48 CDRW of *** kicking thanks so some firmware updates
    SB LIVE! Value
    Altec Lansing ACS 54W
    Soyo 7KCA+ or something like that

  8. #8
    Catfish binjured's Avatar
    Join Date
    May 2001
    Location
    Cinci,OH
    Posts
    200
    Fixed (I believe):

    #include <iostream.h>
    //#include <stdafx.h> /* This header file is needed in Visual C++ as far as i know, if you're not using it just leave it commented*/
    int main ()

    {
    int earn=0;

    cin >> "Enter your wage";
    if(earn<6000)
    cout << "\nYou dont pay tax" << endl;
    if((earn>5000) && (earn<20000));
    cout << "\nYou have to pay 20%" << endl;
    if(earn>=20000)
    cout << "\nYou pay 90%" << endl;

    return 0;
    }

    /*Try and use more spaces in your coding, it will help a lot and remember to define your variables by giving them a value*/
    [-Personal Rig-]
    EP-8k5a2+
    AMD Athlon XP 2200+
    512mb pc2700 DDR RAM
    80gb WD "SE" HDD
    40x Liteon CD-RW
    19' Trinitron p991 FD Monitor
    Sapphire Radeon 9700 Pro
    Cable (RR)
    Windows XP Pro
    ------------------

  9. #9
    Great White Shark Wurm's Avatar
    Join Date
    Feb 2001
    Location
    Grafenwöhr / Deutschland
    Posts
    10,757
    Next time try posting your Question HERE!!
    War... War never changes.

  10. #10
    Cartoon Shark jester22c's Avatar
    Join Date
    May 2001
    Location
    between my headphones
    Posts
    4,372
    Originally posted by binjured
    //#include <stdafx.h> /* This header file is needed in Visual C++ as far as i know, if you're not using it just leave it commented*/
    Nope you don't have to include it not in the last few versions I've used any way.
    #Download Firefox# Playing: TF2
    [Main Rig]
    [EVGA P55 SLI] [i7 860 @ 3.6] [Cooler Master Hyper 212 Plus] [8GB Corsair DDR3 1600]
    [Intel G2 80GB SSD] [MSI GTX260 OC] [NEC ea231wmi] [X-Fi > Z-Audio Lambda > Senn HD-580s]

    [Server]
    [MSI K8N Neo4 SLI] [Opteron 175 @ 2.9] [TT Big Typhoon] [2GB Corsair DDR]

  11. #11
    Expensive Sushi
    Join Date
    Jan 2002
    Location
    Avon
    Posts
    23

    Try this

    Try this, looks like it should work.

    #include<iostream.h>
    int main ()

    {
    int earn = 0;

    cout << "Enter your wage: ";
    cin >> earn;
    if (earn<6000)
    cout<<"You dont pay tax."<<endl;
    if ((earn>5000) && (earn<20000))
    cout<<"You have to pay 20%."<<endl;
    if (earn>=20000)
    cout<<"You pay 90%."<<endl;

    return 0;

    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •