Hello People,

I took a class in C++ about a year ago and really liked learning to write code and working with with programs. I did not do very well in the class, in fact i ended up with a C-. Recently I decide that I wanted to try agin, this time for for my own reasons instead of just trying to get the 3 credits of computer science out of the way.

I would like to reach out to anyone that can help me remember how to get started. I have some of the source codes I wrote for the in class and held on to the text book(starting out with C++). I am planning on going though the whole book problem by problem.

My question may seem elementrey to many of you but, I would really appreciat any guidence you can give me.

I want to run the code in the command prompt window. I have downloaded Dev C++, and copied the code from my email to the Dev C++ program. What do I do from here in the command prompt. If I remember correctly, Ineed to save the file, then open it in the command prompt and complie then run the same file with a .cpp to get it to work. My problem is im not sure what the cammands are to get to the file, compile it, and run it.

Any Advice would be wounderful

Have a nice Day!!!

Member Avatar for iamthwee

Just hit the compile run button.

Here is the code i am trying, it lets me enter the numbers, but than exits the command prompt right after. Can i open the file and run it in the command prompt. with (g++ -o something) How do find the file, compile , and run right from the command prompt without it closing

// This program asks the user to enter an item's wholesale cost and
// its markup pecentage. It then displays the items retailprice.
// Inputs: Gets the wholesale cost of the item, and markup percentage.
// Outputs: Displays the retail price of the item.
// Programmer:David Pfaff
// Date: March 28, 2008
// Username: dpfaff

#include <iostream>
#include <iomanip>
using namespace std;

// prints a number of new lines on the screen
// input: num, the number of new lines
// output: num new lines
// usage: printNewLines(3);
void printNewLines (int num);

// gets a wholesale cost from the user
// inputs: a wholesale amount from the user
// outputs: the wholesale cost is returned
// usage: wholeSale = GetwholeSale();
double GetwholeSale();

// gets a markup percentage from the user
// inputs: a markup percentage from the user
// outputs: the markup percentage is returned
// usage: markUp = GetmarkUp();
double GetmarkUp();

// calculates the new retail price of the item
// inputs: a wholesale cost and markup percentage
// outputs: the retail price is returned
// usage: calcRetail = CalcRetail(wholeSale, markUp);
double calcRetail(double wholeSale, double markUp);

// displays the retail price
// inputs: the calculated retail price
// outputs: retail price
// usage: display calcRetail(calcRetail);
void displayRetail(double retailPrice);

int main()
{
   double wholeSale;
   double markUp;
   double retailPrice;

   printNewLines(3);
   
   cout << "David Pfaff\n";
   cout << "March 28, 2008\n";
   cout << "dpfaff\n\n";
   cout << "This program asks the user to enter an item's wholesale cost and\n";
   cout << "its markup pecentage. It then displays the items retail price.\n\n";
   cout << "Inputs: Gets the wholesale cost of the item, and markup percentage.\n";
   cout << "Outputs: Displays the retail price of the item.\n";
   
   printNewLines(3);
   wholeSale = GetwholeSale();
   printNewLines(3);
   
   markUp = GetmarkUp();
   printNewLines(3);
   
   retailPrice = calcRetail(wholeSale, markUp);
   displayRetail(retailPrice);
   printNewLines(2);
   
   return 0;
}

// gets a wholesale cost from the user
// inputs: a wholesale amount from the user
// outputs: the wholesale cost is returned
// usage: wholeSale = GetwholeSale();
double GetwholeSale()
{
   double wholeSale;
   cout << "Enter the wholesale cost -> ";
   cin >> wholeSale;
   while (wholeSale < 0)
   {
      cout << "Error. Enter a positive value -> ";
      cin >> wholeSale;
   }
   return wholeSale;
}

// gets a markup percentage from the user
// inputs: a markup percentage from the user
// outputs: the markup percentage is returned
// usage: markUp = GetmarkUp();
double GetmarkUp()
{
   double markUp;
   cout << "Enter the markup percentage -> ";
   cin >> markUp;
   while (markUp < 0)
   {
      cout << "Error. Enter a positive value -> ";
      cin >> markUp;
   }
   return markUp;
}

// calculates the new retail price of the item
// inputs: a wholesale cost and markup percentage
// outputs: the retail price is returned
// usage: calcRetail = calcRetail(wholeSale, markUp);
double calcRetail(double wholeSale, double markUp)
{
   double calcRetail;
   calcRetail = (wholeSale * (markUp / 100)) + wholeSale;
   return calcRetail;
}

// displays the retail price
// inputs: the calculated retail price
// outputs: retail price
// usage: display(calcRetail);
void displayRetail(double retailPrice)
{
   cout << "The retail price is -> $ " << setprecision(2) << fixed << retailPrice << endl;
} 

// prints a number of new lines on the screen
// input: num, the number of new lines
// output: num new lines
// usage: printNewLines(3);
void printNewLines (int num)
{
   for (int i = 0; i < num; i++)
      cout << endl;
}

?

??it lets me enter the numbers, but than exits the command prompt right after

It may be doing everything you want but just not keeping the console screen open so you can see it because it's not been told to do that. Whern the program is done, the console closes as soon as the last command is finished before the return 0; line in main(). Put a line to to the console open just before the line return 0; if you want to see some of your handiwork. There are several versions. Some use the line cin.get(); others use a call to cin >> using a dummy variable. Others use a system call to pause (though this is generally considered the least desireable version).

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.