C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
learning to program. please help. Posted by dbrio on 19 Oct 2006 at 6:15 PM
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 <iostream> // input/output declarations
#include <iomanip> // 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;
}
Report
Re: learning to program. please help. Posted by shaolin007 on 19 Oct 2006 at 6:27 PM
: 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 <iostream>      // input/output declarations
: #include <iomanip>       // i/o manupulator declarations
: using namespace std;
 function not needed
: // function prototypes
:    float product( float firstnumber, float secondnumber, float lastnumber );
: 
: 
: int main()
: {
:     float firstnumber;     // First number
:     float secondnumber;    // Second number
:     float lastnumber;      // Third number
:     not neededfloat 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
:  not needed   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;
sum and average can be done the same way as product 
:     return 0;
: }


Report
Re: learning to program. please help. Posted by dbrio on 19 Oct 2006 at 6:43 PM
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.
:
: : 
: : #include <iostream>      // input/output declarations
: : #include <iomanip>       // i/o manupulator declarations
: : using namespace std;
:  function not needed
: : // function prototypes
: :    float product( float firstnumber, float secondnumber, float lastnumber );
: : 
: : 
: : int main()
: : {
: :     float firstnumber;     // First number
: :     float secondnumber;    // Second number
: :     float lastnumber;      // Third number
: :     not neededfloat 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
: :  not needed   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;
: sum and average can be done the same way as product 
: :     return 0;
: : }
: 
: 

:

Report
Re: learning to program. please help. Posted by shaolin007 on 19 Oct 2006 at 6:46 PM
: 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.
: :
: : : 
: : : #include <iostream>      // input/output declarations
: : : #include <iomanip>       // i/o manupulator declarations
: : : using namespace std;
: :  function not needed
: : : // function prototypes
: : :    float product( float firstnumber, float secondnumber, float lastnumber );
: : : 
: : : 
: : : int main()
: : : {
: : :     float firstnumber;     // First number
: : :     float secondnumber;    // Second number
: : :     float lastnumber;      // Third number
: : :     not neededfloat 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
: : :  not needed   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;
: : sum and average can be done the same way as product 
: : :     return 0;
: : : }
: : 
: : 

: :
:
:

Try putting right before return 0 a system("pause") and #include <cstdlib> to pause screen.


Report
Re: learning to program. please help. Posted by dbrio on 19 Oct 2006 at 7:10 PM
It worked, thanks.

: : 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.
: : :
: : : : 
: : : : #include <iostream>      // input/output declarations
: : : : #include <iomanip>       // i/o manupulator declarations
: : : : using namespace std;
: : :  function not needed
: : : : // function prototypes
: : : :    float product( float firstnumber, float secondnumber, float lastnumber );
: : : : 
: : : : 
: : : : int main()
: : : : {
: : : :     float firstnumber;     // First number
: : : :     float secondnumber;    // Second number
: : : :     float lastnumber;      // Third number
: : : :     not neededfloat 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
: : : :  not needed   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;
: : : sum and average can be done the same way as product 
: : : :     return 0;
: : : : }
: : : 
: : : 

: : :
: :
: :
:
: Try putting right before return 0 a system("pause") and #include <cstdlib> to pause screen.
:

:
:

Report
Re: learning to program. please help. Posted by bluj91 on 19 Oct 2006 at 8:36 PM
: It worked, thanks.
:
: : : 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.
: : : :
: : : : : 
: : : : : #include <iostream>      // input/output declarations
: : : : : #include <iomanip>       // i/o manupulator declarations
: : : : : using namespace std;
: : : :  function not needed
: : : : : // function prototypes
: : : : :    float product( float firstnumber, float secondnumber, float lastnumber );
: : : : : 
: : : : : 
: : : : : int main()
: : : : : {
: : : : :     float firstnumber;     // First number
: : : : :     float secondnumber;    // Second number
: : : : :     float lastnumber;      // Third number
: : : : :     not neededfloat 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
: : : : :  not needed   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;
: : : : sum and average can be done the same way as product 
: : : : :     return 0;
: : : : : }
: : : : 
: : : : 

: : : :
: : :
: : :
: :
: : Try putting right before return 0 a system("pause") and #include <cstdlib> to pause screen.
: :

: :
: :
:
:

My only comment is that what is <iomanip>, 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.

Report
Re: learning to program. please help. Posted by dbrio on 19 Oct 2006 at 8:40 PM
Ok thanks, thats actually what it ws. When I ran the program through CMD prompt it worked, as opposed to the compile and run feature. Thanks for tip.

Report
Re: learning to program. please help. Posted by shaolin007 on 19 Oct 2006 at 10:12 PM

: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.
:
:

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.

Report
Re: learning to program. please help. Posted by bluj91 on 22 Oct 2006 at 5:14 PM
:
: :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.
: :
: :
:
: 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.
:

:

it just doesn't look nice, also since console applications are intended to be run from the console it is simply unneeded.
Report
Re: learning to program. please help. Posted by shaolin007 on 22 Oct 2006 at 6:15 PM

: it just doesn't look nice, also since console applications are intended to be run from the console it is simply unneeded.
:


Your opinion. I say, use whatever works.






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.