d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Basic C++ Help
Add Reply New Topic New Poll
Member
Posts: 1,173
Joined: Apr 9 2014
Gold: 7.62
Sep 22 2014 03:19pm
How do you write a program to take two double numbers from a keyboard and display their sum, their difference, their product, their quotient, and average on screen
here at my college, I didn't learn shit cause they threw me into the course w/o the intro.

Help please, thanks!

Assignment: http://gyazo.com/62b74d48d6c58d286a9723f8e41e2d31

This post was edited by oDieN on Sep 22 2014 03:28pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 22 2014 04:48pm
http://www.cplusplus.com/doc/tutorial/

if you have a very specific question, please post your code snippet with the question. for a generic question like this, see the tutorials.

in particular: Basic input/output, operators, variables, control structure, arrays

This post was edited by carteblanche on Sep 22 2014 04:49pm
Member
Posts: 2,754
Joined: Nov 26 2007
Gold: 1,339.81
Sep 23 2014 07:25am
This will help get you started. Replace the //... lines with your code to calculate and print difference, product, quotient, and average.
Also read the documentation on the functions scanf and printf to better understand them.

http://www.cplusplus.com/reference/cstdio/scanf/

http://www.cplusplus.com/reference/cstdio/printf/

Code
#include <stdio.h>

int main(){

double a,b;
double sum;
double difference;
double product;
double quotient;
double average;

printf("Please enter a number for a : ");
scanf("%lf", &a);

printf("Please enter a number for b : ");
scanf("%lf", &b);

printf("a is %.2lf.\n",a);
printf("b is %.2lf.\n",b);

//set sum
sum=a+b;

//print sum
printf("sum is %.2lf.\n",sum);

//set difference
//...
//print difference
//...

//set product
//...
//print product
//...

//set quotient
//...
//print quotient
//...

//set average
//...
//print average
//...

/*this is just here to prevent the console window from closing right away after the program runs */
scanf("%f", &a);
return 0;
}


This post was edited by labatymo on Sep 23 2014 07:26am
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Sep 23 2014 10:37am
Quote (labatymo @ Sep 23 2014 09:25am)
This will help get you started. Replace the //... lines with your code to calculate and print difference, product, quotient, and average.
Also read the documentation on the functions scanf and printf to better understand them.

http://www.cplusplus.com/reference/cstdio/scanf/

http://www.cplusplus.com/reference/cstdio/printf/

Code
#include <stdio.h>

int main(){

double a,b;
double sum;
double difference;
double product;
double quotient;
double average;

printf("Please enter a number for a : ");
scanf("%lf", &a);

printf("Please enter a number for b : ");
scanf("%lf", &b);

printf("a is %.2lf.\n",a);
printf("b is %.2lf.\n",b);

//set sum
sum=a+b;

//print sum
printf("sum is %.2lf.\n",sum);

//set difference
//...
//print difference
//...

//set product
//...
//print product
//...

//set quotient
//...
//print quotient
//...

//set average
//...
//print average
//...

/*this is just here to prevent the console window from closing right away after the program runs */
scanf("%f", &a);
return 0;
}


That's some awesome cpp.
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 23 2014 12:15pm
It may be technically legit C++, but it just reeks of C.

@op what's the problem exactly? The instruction tells you exactly what to do.
Member
Posts: 2,754
Joined: Nov 26 2007
Gold: 1,339.81
Sep 23 2014 12:48pm
Quote (KrzaQ2 @ Sep 23 2014 02:15pm)
It may be technically legit C++, but it just reeks of C.

@op what's the problem exactly? The instruction tells you exactly what to do.


It is C. The assignment says "Write a C program".
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 23 2014 12:56pm
Quote (labatymo @ 23 Sep 2014 20:48)
It is C. The assignment says "Write a C program".
Sure, but the topic says "Basic C++ Help". Shame on me for missing that, though.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll