Thread: Can you fix this crap please?

  1. #1
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321

    Unhappy Can you fix this crap please?

    This program should calculate electricity bills......but it dosen't compile in Dev C++
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
        char name[50];
        int units;
        float total;
        start:
        /*Getdata*/
        cout<<"\n\nEnter the costumer's name::";
        cin.getline(name,49,"\n");      /*Problems are in this line*/
        cout<<"\n\nEnter no. of units used::";
        cin>>units;
        /*calculate*/
        if(units<=100)
                      total=units*60/100;
        else if(units<=300)
                        total=60+((units-100)*80/100);
        else if(units>300)
                       total=220+((units-300)*90/100);
        if(total<50)
                    total=50;
        if(total>300)
                     total=total+(0.15*total);
        /*display*/
        cout<<endl<<"Customer's name:"<<name<<endl;
        cout<<"Units:"<<units<<endl;
        cout<<"TOTAL:Rs."<<total<<"only"<<endl;
        cout<<"Another Bill?(y/n)";
        char ano;
        cin>>ano;
        if(ano=='y')
                    goto start;
        cin.get();
        return 0;
    }
    Thanks!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    cin.getline(name,49,"\n");
    should be:
    cin.getline(name,49,'\n');
    Incidentally, use a loop, not a label with goto.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    "\n" is not the same as '\n'.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You really don't need to use /* and */ in C++. A simple // will do in most cases.
    "\n" = \n, \0 (thus, it's char*, or char[2], not char)
    '\n' = \n (thus it's char)
    Simplified explanation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321

    .

    Thank you everyone!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. compiling my code, i can't fix error
    By howru in forum C Programming
    Replies: 2
    Last Post: 04-22-2008, 03:38 AM
  3. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  4. Help me fix my mess!!!!
    By Starr in forum C++ Programming
    Replies: 35
    Last Post: 02-01-2006, 03:40 PM
  5. Anybody fix this simple code?
    By Killinger in forum C++ Programming
    Replies: 25
    Last Post: 08-09-2004, 01:53 PM