C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 21st, 2004, 11:51 AM
Etarr18 Etarr18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 Etarr18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old September 21st, 2004, 01:14 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
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-

Reply With Quote
  #3  
Old September 21st, 2004, 01:26 PM
Etarr18 Etarr18 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 Etarr18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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"

Reply With Quote
  #4  
Old September 21st, 2004, 05:53 PM
The Phantom The Phantom is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: In the Dark City
Posts: 46 The Phantom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to The Phantom
Quote:
. 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"

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;

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Basic C++ help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT