I am trying to learn how to program in C++. I have an assignment that requires me to take three numbers and find the product, the sum, and the average. Here is what I have so far, after I enter in my three numbers the window closes and does not give me the product. Please help.
#include // input/output declarations
#include // i/o manupulator declarations
using namespace std;
// function prototypes
float product( float firstnumber, float secondnumber, float lastnumber );
int main()
{
float firstnumber; // First number
float secondnumber; // Second number
float lastnumber; // Third number
float product; // The product of all 3 numbers
// Set up floating point output format
cout << fixed << showpoint << setprecision(2);
// Entering three numbers for computation
cout << "Enter first number: ";
cin >> firstnumber;
cout << "Enter second number: ";
cin >> secondnumber;
cout << "Enter last number: ";
cin >> lastnumber;
// Product of 3 numbers
product = firstnumber, secondnumber, lastnumber ;
// Print
cout << " If these numbers are used:" << endl;
cout << " " << firstnumber << " first number" << endl;
cout << " " << secondnumber << " second number" << endl;
cout << " " << lastnumber << " third number" << endl;
cout << " the product will be " << product << endl;
return 0;
}
Comments
[code]
:
: #include // input/output declarations
: #include // i/o manupulator declarations
: using namespace std;
[red] function not needed[/red]
: // function prototypes
: float product( float firstnumber, float secondnumber, float lastnumber );
:
:
: int main()
: {
: float firstnumber; // First number
: float secondnumber; // Second number
: float lastnumber; // Third number
: [red]not needed[/red]float product; // The product of all 3 numbers
:
: // Set up floating point output format
: cout << fixed << showpoint << setprecision(2);
:
: // Entering three numbers for computation
: cout << "Enter first number: ";
: cin >> firstnumber;
: cout << "Enter second number: ";
: cin >> secondnumber;
: cout << "Enter last number: ";
: cin >> lastnumber;
:
: // Product of 3 numbers
: [red]not needed[/red] product = firstnumber, secondnumber, lastnumber ;
:
: // Print
: cout << " If these numbers are used:" << endl;
: cout << " " << firstnumber << " first number" << endl;
: cout << " " << secondnumber << " second number" << endl;
: cout << " " << lastnumber << " third number" << endl;
: cout << " the product will be " << firstnumber*secondnumber*lastnumber << endl;
[red]sum and average can be done the same way as product[/red]
: return 0;
: }
[/code]
: : I am trying to learn how to program in C++. I have an assignment that requires me to take three numbers and find the product, the sum, and the average. Here is what I have so far, after I enter in my three numbers the window closes and does not give me the product. Please help.
: [code]
: :
: : #include // input/output declarations
: : #include // i/o manupulator declarations
: : using namespace std;
: [red] function not needed[/red]
: : // function prototypes
: : float product( float firstnumber, float secondnumber, float lastnumber );
: :
: :
: : int main()
: : {
: : float firstnumber; // First number
: : float secondnumber; // Second number
: : float lastnumber; // Third number
: : [red]not needed[/red]float product; // The product of all 3 numbers
: :
: : // Set up floating point output format
: : cout << fixed << showpoint << setprecision(2);
: :
: : // Entering three numbers for computation
: : cout << "Enter first number: ";
: : cin >> firstnumber;
: : cout << "Enter second number: ";
: : cin >> secondnumber;
: : cout << "Enter last number: ";
: : cin >> lastnumber;
: :
: : // Product of 3 numbers
: : [red]not needed[/red] product = firstnumber, secondnumber, lastnumber ;
: :
: : // Print
: : cout << " If these numbers are used:" << endl;
: : cout << " " << firstnumber << " first number" << endl;
: : cout << " " << secondnumber << " second number" << endl;
: : cout << " " << lastnumber << " third number" << endl;
: : cout << " the product will be " << firstnumber*secondnumber*lastnumber << endl;
: [red]sum and average can be done the same way as product[/red]
: : return 0;
: : }
:
: [/code]
:
:
: : : I am trying to learn how to program in C++. I have an assignment that requires me to take three numbers and find the product, the sum, and the average. Here is what I have so far, after I enter in my three numbers the window closes and does not give me the product. Please help.
: : [code]
: : :
: : : #include // input/output declarations
: : : #include // i/o manupulator declarations
: : : using namespace std;
: : [red] function not needed[/red]
: : : // function prototypes
: : : float product( float firstnumber, float secondnumber, float lastnumber );
: : :
: : :
: : : int main()
: : : {
: : : float firstnumber; // First number
: : : float secondnumber; // Second number
: : : float lastnumber; // Third number
: : : [red]not needed[/red]float product; // The product of all 3 numbers
: : :
: : : // Set up floating point output format
: : : cout << fixed << showpoint << setprecision(2);
: : :
: : : // Entering three numbers for computation
: : : cout << "Enter first number: ";
: : : cin >> firstnumber;
: : : cout << "Enter second number: ";
: : : cin >> secondnumber;
: : : cout << "Enter last number: ";
: : : cin >> lastnumber;
: : :
: : : // Product of 3 numbers
: : : [red]not needed[/red] product = firstnumber, secondnumber, lastnumber ;
: : :
: : : // Print
: : : cout << " If these numbers are used:" << endl;
: : : cout << " " << firstnumber << " first number" << endl;
: : : cout << " " << secondnumber << " second number" << endl;
: : : cout << " " << lastnumber << " third number" << endl;
: : : cout << " the product will be " << firstnumber*secondnumber*lastnumber << endl;
: : [red]sum and average can be done the same way as product[/red]
: : : return 0;
: : : }
: :
: : [/code]
: :
:
:
[green]
Try putting right before return 0 a system("pause") and #include <cstdlib> to pause screen.
[/green]
: : I tried making those changes, and still same outcome. I then entered your code minus the : of course and still same outcome. Could it be XP not letting me continue running the program.
: :
: : : : I am trying to learn how to program in C++. I have an assignment that requires me to take three numbers and find the product, the sum, and the average. Here is what I have so far, after I enter in my three numbers the window closes and does not give me the product. Please help.
: : : [code]
: : : :
: : : : #include // input/output declarations
: : : : #include // i/o manupulator declarations
: : : : using namespace std;
: : : [red] function not needed[/red]
: : : : // function prototypes
: : : : float product( float firstnumber, float secondnumber, float lastnumber );
: : : :
: : : :
: : : : int main()
: : : : {
: : : : float firstnumber; // First number
: : : : float secondnumber; // Second number
: : : : float lastnumber; // Third number
: : : : [red]not needed[/red]float product; // The product of all 3 numbers
: : : :
: : : : // Set up floating point output format
: : : : cout << fixed << showpoint << setprecision(2);
: : : :
: : : : // Entering three numbers for computation
: : : : cout << "Enter first number: ";
: : : : cin >> firstnumber;
: : : : cout << "Enter second number: ";
: : : : cin >> secondnumber;
: : : : cout << "Enter last number: ";
: : : : cin >> lastnumber;
: : : :
: : : : // Product of 3 numbers
: : : : [red]not needed[/red] product = firstnumber, secondnumber, lastnumber ;
: : : :
: : : : // Print
: : : : cout << " If these numbers are used:" << endl;
: : : : cout << " " << firstnumber << " first number" << endl;
: : : : cout << " " << secondnumber << " second number" << endl;
: : : : cout << " " << lastnumber << " third number" << endl;
: : : : cout << " the product will be " << firstnumber*secondnumber*lastnumber << endl;
: : : [red]sum and average can be done the same way as product[/red]
: : : : return 0;
: : : : }
: : :
: : : [/code]
: : :
: :
: :
: [green]
: Try putting right before return 0 a system("pause") and #include <cstdlib> to pause screen.
: [/green]
:
:
:
: : : I tried making those changes, and still same outcome. I then entered your code minus the : of course and still same outcome. Could it be XP not letting me continue running the program.
: : :
: : : : : I am trying to learn how to program in C++. I have an assignment that requires me to take three numbers and find the product, the sum, and the average. Here is what I have so far, after I enter in my three numbers the window closes and does not give me the product. Please help.
: : : : [code]
: : : : :
: : : : : #include // input/output declarations
: : : : : #include // i/o manupulator declarations
: : : : : using namespace std;
: : : : [red] function not needed[/red]
: : : : : // function prototypes
: : : : : float product( float firstnumber, float secondnumber, float lastnumber );
: : : : :
: : : : :
: : : : : int main()
: : : : : {
: : : : : float firstnumber; // First number
: : : : : float secondnumber; // Second number
: : : : : float lastnumber; // Third number
: : : : : [red]not needed[/red]float product; // The product of all 3 numbers
: : : : :
: : : : : // Set up floating point output format
: : : : : cout << fixed << showpoint << setprecision(2);
: : : : :
: : : : : // Entering three numbers for computation
: : : : : cout << "Enter first number: ";
: : : : : cin >> firstnumber;
: : : : : cout << "Enter second number: ";
: : : : : cin >> secondnumber;
: : : : : cout << "Enter last number: ";
: : : : : cin >> lastnumber;
: : : : :
: : : : : // Product of 3 numbers
: : : : : [red]not needed[/red] product = firstnumber, secondnumber, lastnumber ;
: : : : :
: : : : : // Print
: : : : : cout << " If these numbers are used:" << endl;
: : : : : cout << " " << firstnumber << " first number" << endl;
: : : : : cout << " " << secondnumber << " second number" << endl;
: : : : : cout << " " << lastnumber << " third number" << endl;
: : : : : cout << " the product will be " << firstnumber*secondnumber*lastnumber << endl;
: : : : [red]sum and average can be done the same way as product[/red]
: : : : : return 0;
: : : : : }
: : : :
: : : : [/code]
: : : :
: : :
: : :
: : [green]
: : Try putting right before return 0 a system("pause") and #include <cstdlib> to pause screen.
: : [/green]
: :
: :
:
:
My only comment is that what is , I don't believe you need this for yor assignment and furthermore, you probably just want to run console applications from the console, ie. cmd.exe, command.com, bash, whatever...; as using system("pause"); to pause an application a bit horrible looking and probably should not be in you program's source when you hand it in.
:using system("pause"); to pause an application a bit horrible looking and probably should not be in you program's source when you hand it in.
:
:
[green]
Whats so horrible about it? My c++ instructor doesn't seem to have a problem with it not including the fact he uses it for simple programs. Now if you were shooting for portability, then no, I wouldn't use it.
[/green]
: :using system("pause"); to pause an application a bit horrible looking and probably should not be in you program's source when you hand it in.
: :
: :
: [green]
: Whats so horrible about it? My c++ instructor doesn't seem to have a problem with it not including the fact he uses it for simple programs. Now if you were shooting for portability, then no, I wouldn't use it.
: [/green]
:
it just doesn't look nice, also since console applications are intended to be run from the console it is simply unneeded.
: it just doesn't look nice, also since console applications are intended to be run from the console it is simply unneeded.
:
[green]
Your opinion. I say, use whatever works.
[/green]