| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Basic C++ help
The following is code to take 3 input values and determine if they are between 1-25 to satisfy a triangle.
#include <iostream> using namespace std; int main () { int v1(0), v2(0), v3(0); cout << "COMP 160 Eric Tarr" << endl; cout << "Section 1 450011" << endl; cout << "Assignment #3 September 17, 2004" << endl << endl; cout << "This program will determine if three user-entered values satisfy the triangle inequality." << endl << endl; cout << "Please enter the first input value (between 1 and 25):"; cin >> v1; cout << endl << endl; cout << "Please enter the second input value (between 1 and 25):"; cin >> v2; cout << endl << endl; cout << "Please enter the third inpute value (between 1 and 25):"; cin >> v3; cout << endl << endl; if ( v1 && v2 && v3 >= 1 && v1 && v2 && v3 <= 25) cout << "The numbers v1, v2 and v3 do satisfy the triangle inequaliy."; if ( v1 && v2 && v3 < 1 && v1 && v2 && v3 >25) cout << "The numbers v1, v2 and v3 do not satisfy the triangle inequality."; else if ( v1 <=1 && v1 <= 25 ) { cout << "Please enter the first input value (between 1 and 25):"; cin >> v1; v1 = 1; } else if( v2 <=1 && v2 <= 25 ) { cout << "Please enter the second input value (between 1 and 25):"; cin >> v2; v2 = 1; } else if (v3 <=1 && v3 <= 25 ) { cout << "Please enter the third input value (between 1 and 25):"; cin >> v3; v3 =1; } return 0; } Im to take 3 numbers and print out if they are in range or out of range. If they are out of range im too reset the value to 1 and have the user input another value. |
|
#2
|
|||
|
|||
|
You have said what you need to do and given the code but have made no mention of the problem you have or the question you want answered...
-KM- |
|
#3
|
|||
|
|||
|
I can't get it to output right, If one of the numbers is not in the range I have set then I need the value to reset to 1 and have that number sent back in by the user.
Made some adjustments but still can't get things to print out correctly. #include <iostream> using namespace std; int main () { float v1(0), v2(0), v3(0); cout << "COMP 160 Eric Tarr" << endl; cout << "Section 1 450011" << endl; cout << "Assignment #3 September 17, 2004" << endl << endl; cout << "This program will determine if three user-entered values satisfy the triangle inequality." << endl << endl; cout << "Please enter the first input value (between 1 and 25): "; cin >> v1; cout << v1; cout << endl << endl; cout << "Please enter the second input value (between 1 and 25): "; cin >> v2; cout << v2; cout << endl << endl; cout << "Please enter the third inpute value (between 1 and 25): "; cin >> v3; cout << v3; cout << endl << endl; if ( v1 >= 1 && v2 >=1 && v3 >= 1 && v1 <=25 && v2 <=25 && v3 <= 25) cout << "The numbers v1, v2 and v3 do satisfy the triangle inequaliy."; else cout << "The numbers v1, v2 and v3 do not satisfy the triangle inequality."; cout << endl << endl; if( 1 < v1 || v1 > 25 ) { cout << "Please enter the first input value (between 1 and 25):"; cout << v1; cout << endl; cout << "The first input value v1 is not greater than or equal to one and less than or equal to 25. Your value has been reset to one." << endl; v1 = 1; cin >> v1; } else if ( 1 < v2 || v2 > 25 ) { cout << "Please enter the second input value (between 1 and 25):"; cout << v2; cout << endl; cout << "The second input value v2 is not greater that or equal to one and less than or equal to 25. Your value has been reset to one." << endl; v2 = 1; cin >> v2; } else if( 1 < v3 || v3 > 25 ) { cout << "Please enter the third input value (between 1 and 25):"; cout << v3; cout << endl; cout << "The third in put value v3 is not greater than or equal to one and less than or equal to 25. Your value has been reset to one." << endl; v3 = 1; cin >> v3; } return 0; } 1. do I need to use float or int? 2. how do I get the last If statements to print when the values are not in the right range. 3. also how do I get it to print the value in a sentence instead of "v1" |
|
#4
|
|||
|
|||
|
Quote:
1. use "int" 2. i would use the "switch" statement 3. (<go like this>) cout << " hi my name is the phantom" << v1 << "this is the answer" << endl; |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Basic C++ help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|