ok so yesterday i had issues with devc++ (where my code occasionally compiled) and when i tried to run the "compiled" program it says "source not compiled" (when really..i hit the compile button).

So..i have now installed Visual c++ 2008, and i cant create a new project, it just says "Automation server cant create object!).

Then,....i move onto Code::Blocks C++ compiler; and i paste in the following from my previous devc++.

/*A program that calculates the area and the perimether of rectangular piece of land*/
#include <iostream.h>
typedef unsigned short int pint;
int main()
{
    pint width;
    pint length;
    pint area=(width*length);
    pint perM=( (width+width) + (length+length) );
    
    pint answer;
    
    cout<<"Enter the width of the land:\n";
    cin>> width;
    cout<<"Enter the length of the land:\n";
    cin>>length;
    
    cout<<"\nPress 1 to calculate the area 'or' Press 2 to calculate the perimeter\n";
    cin>> answer;
    
{
    if (answer == 1)
               {
               cout<<"The area of the land is:" << area << "m2";
               }
               
    if (answer == 2)
               {
               cout<<"The perimeter is:" << perM << "meters";
               }
    else
    {
        if (answer > 2)
        cout<<"I said press 1 or 2; not press some other random button!!!";
    }
}

so after pasting that i go build>"compile current file" on code::blocks
and then nothing happens!!!,

Im confused and i cannot even run my code (which....i spent 30mins doing, keep in mind im a newbie)

Any suggestions as to why all this is happening? and is there anything i can do? is my code correct?

(edit2:: the same problem from devc++ is in code::blocks now??!)

Dani AI

Generated

Quick diagnosis: there are two separate problem classes here — code logic/undefined behavior and IDE/toolchain configuration. As pointed out, some calculations are being done before the program reads values; that will produce garbage results. Separately, IDEs (Dev-C++, Code::Blocks, Visual C++) can appear to "do nothing" when the source never actually builds into an executable because the file was unsaved, the compiler/toolchain is not configured, or the build action used doesn't create a linked program.

Code fixes and good practices:

  • Do not compute area/perimeter until after cin has read width and length. Uninitialized numeric variables hold indeterminate values (undefined behavior).
  • Use a current header (<iostream>) and qualify std::cin/std::cout (or using namespace std;) so modern compilers accept the code.
  • Use a sensible integer type (e.g., int) unless you intentionally need a narrow unsigned type; watch for overflow on small fixed-width types.
  • Structure input-choice logic with if / else if / else or a switch so the "else" branch can't run unexpectedly.
  • Always check input (e.g., verify cin succeeded) and return from main explicitly (return 0;).

IDE / compiler troubleshooting (step-by-step):

  • Save the file and give it a .cpp extension. Try a simple command-line compile to isolate the IDE:
g++ -Wall -Wextra -std=c++11 -o land land.cpp
  • In Code::Blocks go to Settings -> Compiler and Debugger -> Global compiler settings and confirm a compiler is selected and Toolchain Executables point to Mingw/GCC. If you installed Code::Blocks without MinGW, nothing will compile.
  • Use the Build/Compile log or "Build messages" tab — it contains the actual errors. "Source not compiled" simply means the compile step failed; read the messages.

Visual C++ 2008 note:

  • "Automation server can't create object!" usually indicates an installation/registration or permission problem with the IDE. Try running the IDE as Administrator, then repair or reinstall Visual C++ if the error persists. After fixing the toolchain, rebuild the corrected source.

> pint area=(width*length);
> pint perM=( (width+width) + (length+length) );
How about moving these lines to AFTER you have input the values. Expressions are evaluated at the point you write them. They're not some kind of "rule" continually updated when new information (say cin >> width) happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.