need help with conditional statements

any idea why it wont compile in unix?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
//-| ---------------------------------------------------------------
//-| Assignment ID: PROG6a   
//-| File name:     drinking.cpp
//-| Due:           Wednesday, Mar 14 at 10 am
//-| Author: bfields Byron Fields
//-| Description:  Determine if someone is of drinking age.
//-| ---------------------------------------------------------------

#include <iostream>
#include <cmath>
using namespace std;

int main ()
 {

//-| ----------------------------------  
//-| Declare Variables
//-| ----------------------------------  

float CreditHours;
int Age;
   
//-| --------------------------------------
//-| Prompt user to enter #college credits
//-| --------------------------------------
cout << "Enter #college credits:" << endl;
    
//-| -------------------------------------
//-| Read number of college credits
//-| -------------------------------------
cin >> CreditHours >> endl;

//-| -----------------------------------
//-| Prompt user to enter age
//-| -----------------------------------
cout << "Enter your age" << endl;

//-| ----------------------------------
//-| Read Age
//-| ----------------------------------
cin >> Age >> endl;

//-| ------------------------------------
//-| Display " You are "+Age+" years old"
//-| ------------------------------------
cout << "You are "+Age+" years old" << endl;

//-| ------------------------------------
//-| If Age >= 21 then yes, else no
//-| ------------------------------------
if ( Age < 21 )
   cout << "You are too young to drink in FL." << endl;
else if ( Age >= 21 && CreditHours > 0 )
   cout << "You are of drinking age in Florida. " << endl;
else if ( Age >= 21 ** CreditHours < 0)
   cout << "You are old enough, but are not enrolled in college. You can NOT drink in FL." << endl;

   return 0;
   }





cin >> CreditHours >> endl; is incorrect.
Get rid of the >> endl part.

Also:
cout << "You are "+Age+" years old" << endl;
That won't quite work like you want it to....
You would need to write
cout << "You are " << Age << " years old" << endl;

And also:
else if ( Age >= 21 ** CreditHours < 0)
I don't know what you mean here.
** is not an operator in C++...(did you mean &&?)
...and how can you have negative college credits?
(also note that if CreditHours is 0, it won't fall under any of the ifs)
It helps if you tell us what the errors are.

But anyway...

1)
cin >> CreditHours >> endl;

You can't put 'endl' on the right side of the >> operator. >> is for "reading into" a variable (ie, here you are reading into CreditHours). endl is a constant so you can't read into it.

You make this mistake again when you get 'Age'.

2)
cout << "You are "+Age+" years old" << endl;

You can't add string literals and integers. You probably want << instead of + here.

3)
else if ( Age >= 21 ** CreditHours < 0)

** is not an operator. You probably meant &&
thanks to you both i got it done. nd i would include my errors but unix just gives me some jumbled mess like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
drinking.cpp:32: no match for `std::basic_istream<char, std::char_traits<char> 
   >& >> <unknown type>' operator
/usr/local/include/c++/3.2.2/bits/istream.tcc:83: candidates are: 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(std::basic_istream<_CharT, 
   _Traits>&(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, 
   _Traits = std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:92:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(std::basic_ios<_CharT, 
   _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits 
   = std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:101:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT = char, 
   _Traits = std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:110:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(bool&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:137:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(short int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:174:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:201:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:238:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:265:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(long int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:292:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:320:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:347:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:375:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(float&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:402:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(double&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:429:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(long double&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:456:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(void*&) [with _CharT = char, _Traits = 
   std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:483:                 
   std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, 
   _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = 
   char, _Traits = std::char_traits<char>]
/usr/local/include/c++/3.2.2/bits/istream.tcc:990:                  
Topic archived. No new replies allowed.