Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102871618
ch-02-ex-02-solution.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 25, 01:46
Size
1 KB
Mime Type
text/x-c
Expires
Thu, Feb 27, 01:46 (2 d)
Engine
blob
Format
Raw Data
Handle
24446673
Attached To
R1106 Programming Concept Rouaze
ch-02-ex-02-solution.cpp
View Options
/*
* chapter-02-exercise-02.cpp
*
* Using the "if" clause
*
* Created on: Aug 19, 2012
* Author: Radu Popescu <radu.popescu@epfl.ch>
*/
#include <iostream>
int main(int argc, char* argv[])
{
double p, q, x, y;
int j;
/*
* Read p
*/
std::cout << "Please input value of p (double): ";
std::cin >> p;
/*
* Read q
*/
std::cout << "Please input value of q (double): ";
std::cin >> q;
/*
* Read y
*/
std::cout << "Please input value of y (double): ";
std::cin >> y;
/*
* Read j
*/
std::cout << "Please input value of j (integer): ";
std::cin >> j;
/*
* Set x to 5 if either p is greater than or equal to q, or the variable
* j is not equal to 10
*/
if ((p >= q) || (j != 10)) {
x = 5;
}
/*
* Set x to 5 if both y is greater than or equal to q, and the variable j
* is equal to 20. Otherwise set x to p
*/
if ((y >= q) && (j == 20)) {
x = 5;
} else {
x = p;
}
/*
* Set x according to rule at ex 2.2.3
*/
if (p > q) {
x = 0;
} else if (j == 10) {
x = 1;
} else {
x = 2;
}
// Print out x
std::cout << "The value of x is: " << x << std::endl;
return 0;
}
Event Timeline
Log In to Comment