LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-12-2012, 10:55 PM   #1
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Rep: Reputation: Disabled
Programming for a class and my program keeps coming back with a bunch of errors


#include <iostream>
#include <math>
using namespace std;
int main ()
{
int yr;
char gender;
int yrd;
yrd = ( 2012 - yr )* 365 * 24 * 60 * 60;
cout << "Enter your year of birth:" << endl;
cin >> yr >> endl;
cout << "Enter your Gender(M/F):" << endl;
cin >> gender >> endl;
{
if ( gender == 'M' || 'm' && yr <= 2012)
cout << "You will die in " << 2.38 * (10^9) * yrd << "seconds" << endl;
else if ( gender == 'F' || 'f' && yr <= 2012)
cout << "You will die in " << 2.548 * (10^9) * yrd <<" seconds" << endl;
else
cout << "Your input was invalid. Run the program again!" << endl;
}

return 0;
}


Here's the link to the assignment and I cant figure out what I'm doing wrong
http://web2.clarkson.edu/class/cs141/project1.html
Thank you for responses
 
Old 09-12-2012, 11:23 PM   #2
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
Maybe if you told us what errors you get,we could help you in the right direction.
 
Old 09-12-2012, 11:31 PM   #3
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
It's not really an error I can write it must be something wrong with it because it's not a simple error its a huge bunch of words I don't understand
 
Old 09-12-2012, 11:33 PM   #4
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
This is part of what I get

no match for ‚operator>>‚ in ‚std::cin.std::basic_istream<_CharT, _Traits>:perator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(& yr))) >> std::endl‚
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>:perator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:134: note: std::basic_istream<_CharT,
 
Old 09-12-2012, 11:35 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

welcome to LQ. Usually people don't answer homework questions here, but I think the way you have asked this one is ok
(ie you've had a good go at it, written some code and are now stuck).

From I quick glance or your code I can see a couple of problems

For instance you have:
Code:
if ( gender == 'M' || 'm' && yr <= 2012)
In this the || will not work the way you seem to expect. I think what you want is:
Code:
if ( (gender == 'M' || gender == 'm') && yr <= 2012)
There are two things here:
1. You need to include the equality test for both 'M' and 'm"
2. When using an || like this you need to be careful that the && is evaluated: hence the brackets.

Additionally I don't think the ^ operator does what you expect.

HTH,

Evo2.

PS. Next time you post such a question, please tell us what happens when you run the code, and why the output is not as you expected.
 
1 members found this post helpful.
Old 09-12-2012, 11:38 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Ahh, now that I see the compiler output: you shouldn't have the ">> endl" on the cin line.

Evo2.
 
1 members found this post helpful.
Old 09-12-2012, 11:41 PM   #7
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
ok now I am just getting this

project1.cpp: In function ‚int main()‚:
project1.cpp:17: error: expected primary-expression before ‚;‚ token
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to compile a program in C++ gives me a bunch of errors ( Total N00b) Ryupower Programming 10 06-21-2007 12:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration