Results 1 to 4 of 4

Thread: Code check again please

  1. #1
    Aerials
    Guest

    Question Code check again please

    Hmm Im trying to make a program that calculates the area of a rectangle and after you get the first rectangle, you can type in C to continue or anything else to stop. It doesnt work though.
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    char cont=c
    double length;
    
    double height;
    for(i=0;cont=c;i++)
    {
    cout<<"This will calculate the area of a rectangle for you.\n"<<endl;
    cout<<"Enter the length of the rectangle: "<<endl;
    cin>>length;
    cout<<"Enter the height of the rectangle: "<<endl;
    cin>>height;
    cout<<"\n The area of the rectangle is: "<<(length*height)<<endl;
    
    cout<<"Type in C to continue or anything else to close the program."<<endl;
    cin>>cont;
    }
    getch();
    getch();
    return 0;
    
    }

  2. #2
    AnT
    Guest
    I tried this...
    PHP Code:
    #include <iostream.h>
    #include <conio.h>
    #include <cstdlib>

    int main(int argccharargv[])
    {
        
    docheck();
        return 
    0;
    }

    int docheck()
    {
    char cont;
    double length;

    double height;
    system("cls");
    cout<<"This will calculate the area of a rectangle for you.\n"<<endl;
    cout<<"Enter the length of the rectangle: "<<endl;
    cin>>length;
    cout<<"Enter the height of the rectangle: "<<endl;
    cin>>height;
    cout<<"\n The area of the rectangle is: "<<(length*height)<<endl;

    cout<<"Type in C to continue or anything else to close the program."<<endl;
    cin>>cont;
    if(
    cont == 'C' || cont == 'c')
    {
        
    docheck();
    }

    getch();
    //return 0;

    I am also pretty much a newb to C++. When I execute this code, I get "undeclared identifier pointing to the docheck(); in main, and a "redefinition; different type modifiers" pointing to the sub docheck(); itself. Help?

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    AnT: you need a function prototype. Put
    int docheck();

    before the main function and you'll be allright.

    Aerials: just a few errors:
    Code:
    #include <iostream>  // the standard changed: you should use this
    #include <conio.h>
    using namespace std;  // this is a resulting necessity
    
    int main()
    {
    char cont='c';  // char literals are to be wrapped in single quotes
    double length;
    
    double height;
    while(cont == 'c')  // better to use a while here, comparison is ==
    {
    cout<<"This will calculate the area of a rectangle for you.\n"<<endl;
    cout<<"Enter the length of the rectangle: "<<endl;
    cin>>length;
    cout<<"Enter the height of the rectangle: "<<endl;
    cin>>height;
    cout<<"\n The area of the rectangle is: "<<(length*height)<<endl;
    
    cout<<"Type in C to continue or anything else to close the program."<<endl;
    cin>>cont;
    }
    getch();
    getch();
    return 0;
    
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You guys might want to use a do while loop, I not at my workstation, but I 'll do an example with a loop when I get home later.

Posting Permissions

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



Click Here to Expand Forum to Full Width