Can you fix this crap please?

This is a discussion on Can you fix this crap please? within the C++ Programming forums, part of the General Programming Boards category; This program should calculate electricity bills......but it dosen't compile in Dev C++ Code: #include<iostream> using namespace std; int main() { ...

  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
    21,717
    cin.getline(name,49,"\n");
    should be:
    cin.getline(name,49,'\n');
    Incidentally, use a loop, not a label with goto.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,185
    "\n" is not the same as '\n'.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    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, 02:40 PM
  5. Anybody fix this simple code?
    By Killinger in forum C++ Programming
    Replies: 25
    Last Post: 08-09-2004, 01:53 PM

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