Hello! I need help writing a program for a class, im having a lot of trouble comprehending with this because this is all new to me, the two main objectives are these:
It first declare three double variables: a, b, and c.
Then it asks the user for three numbers, and assign them to a, b and c respectively. Then it computes the sum and product of the three numbers.
Before printing out each of the sum and product, it should announce what is being calculated. Below is a sample input and output of the program, where the user entered the numbers 3.4, 5.6 and 4.3. There, user inputs are indicated with underlines for a presentation purpose.
1. It first declare three double variables: a, b, and c.
2. Then it asks the user for three numbers, and assign them to a, b and c respectively.
3. Then it computes the sum and product of the three numbers.
If you have problems with any of these points, ask again.
If not, repeat this for the remaining points.
by the way, you can also declare these doubles by using:
double x=5.4, y=4.3, z;
and instead of system("pause") use cin.ignore(numeric_limits<streamsize>::max(), '\n');
This might seem intimidating, but it's a better way to do the same (and faster).. ( see: http://www.cplusplus.com/forum/articles/11153/ )
Also, in the line with z=x/(double) y; you can remove the (double)
Anyway, first try to do what Athar said, and if you need any extra help, feel free to ask :)
Hey guys, thanks for all the help, you've pushed me in the right direction. I just have two simple (noob) questions, how to I make the users input become underlined for the presentational purpose? Also, is there a way I can space out the lines in the debug screen so it doesn't look cluttered? thank you :)
Here is what I have:
#include <iostream>
using namespace std;
int main()
{
//Declare 3 double variables for input and another 2 for the sum and product
double gab1, gab2, gab3, sum, prod;
//ask for value 1
cout<<"Enter value 1: ";
//cin assigns the input to the variable
cin>>gab1;
cout<<"Enter value 2: ";
cin>>gab2;
cout<<"Enter value 3: ";
cin>>gab3;
// Sum of the three double variables
sum = gab1 + gab2 + gab3;
// Show the sum of the three double variables
cout<<"The sum of "<< gab1 << " and " <<gab2<<" and "<<gab3<<" = "<<sum<<"\n";
// Calculate and show the product
prod = gab1 * gab2 * gab3;
cout<<"The product of "<< gab1 << " and " <<gab2<<" and "<<gab3<<" = "<<prod<<"\n";
Try '\b' at the end of your cout statement right before grabbing input.
Each time \b is placed a blank line is inserted that gets overridden which each character entered.
ex: cout<<"Enter value 1: \b\b\b";
Will have 3 spaces of line in the console.
Edit: It might also be something like this:
ex: cout<<"Enter value 1: ___\b\b\b";