#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

bool checkleap(int year);

int main(int argc, char *argv[])

{string s1;
int year,month,day,inbetween,dayspassed;
char dash1,dash2;
s1="Today is day number: ";
bool leapcheck;
leapcheck=checkleap(year);
cout<<"Enter a date, in the form of MM-DD-YYYY: "<<endl;
cin>>month>>dash1>>day>>dash2>>year;
switch (month)
{case 1: 31-day=inbetween;               //Line 19
         31-inbetween=dayspassed;        //Line 20
         cout<<s1<<dayspassed<<endl;
         break;
 case 2: if(leapcheck=true)
         {60-day=inbetween;              //Line 24
         60-inbetween=dayspassed;        //Line 25
         cout<<s1<<dayspassed<<endl;}
         else
         {59-day=inbetween;              //Line 28
         59-inbetween=dayspassed;        //Line 29
         cout<<s1<<dayspassed<<endl;}
         break;
 case 3: if(leapcheck=true)
         {91-day=inbetween;              //Line 33
         91-inbetween=dayspassed;        //Line 34
         cout<<s1<<dayspassed<<endl;}
         else
         {90-day=inbetween;              //Line 37
         90-inbetween=dayspassed;        //Line 38
         cout<<s1<<dayspassed<<endl;}
         break;

system("PAUSE");
return EXIT_SUCCESS;
}

bool checkleap(int year)
{if(year%4=0 && year%100!=0 || year%100=0 && year%400=0) //Line 47
return true;
return false;} //Line 49

Right, so this is what I have been working on thus far. Basically, I'm trying to display the how many days have passed since the beginning of the year (this is determined via data input from the user). I'm obviously not finished yet. What I wanted to do was quickly compile my program to check for errors; I have several, but most are the same kind of error, namely: non ivalue in assignment. Below are all errors picked up by the compiler:

19 non-lvalue in assignment
20 non-lvalue in assignment
24 non-lvalue in assignment
25 non-lvalue in assignment
28 non-lvalue in assignment
29 non-lvalue in assignment
33 non-lvalue in assignment
34 non-lvalue in assignment
37 non-lvalue in assignment
38 non-lvalue in assignment
47 a function-definition is not allowed here before '{' token
47 expected `,' or `;' before '{' token
49 expected `}' at end of input

Recommended Answers

All 10 Replies

You've got your assignments backwards. The receiving variable should be on the left, and the calculation should be on the right. So:

31-day=inbetween

should be:

inbetween = 31 - day;

(Note that the use of spaces in your code makes reading it more understandable.)

Thank you. That solves 90% of my errors. Do you know what is wrong with my function definition?

Well, you don't seem to have a closing brace for your switch function. Get that corrected, post some updated code, and I'll have a look.

I forgot a curly brace after the third case in my switch statement (after the break on case 3).

Well, you don't seem to have a closing brace for your switch function. Get that corrected, post some updated code, and I'll have a look.

Yes, exactly. Now the only error I'm getting is...:

non-lvalue in assignment for the if statement in my function definition

updated code:

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

bool checkleap(int year);

int main(int argc, char *argv[])


{string s1;
int year,month,day,inbetween,dayspassed;
char dash1,dash2;
s1="Today is day number: ";
bool leapcheck;
leapcheck=checkleap(year);
cout<<"Enter a date, in the form of MM-DD-YYYY: "<<endl;
cin>>month>>dash1>>day>>dash2>>year;


switch (month)
{case 1: inbetween=31-day;
         dayspassed=31-inbetween;
         cout<<s1<<dayspassed<<endl;
         break;
 

case 2: if(leapcheck=true)
         {inbetween=60-day;
         dayspassed=60-inbetween;
         cout<<s1<<dayspassed<<endl;}
         else
         {inbetween=59-day;
         dayspassed=59-inbetween;
         cout<<s1<<dayspassed<<endl;}
         break;


 case 3: if(leapcheck=true)
         {inbetween=91-day;
         dayspassed=91-inbetween;
         cout<<s1<<dayspassed<<endl;}
         else
         {inbetween=90-day;
          dayspassed=90-inbetween;
         cout<<s1<<dayspassed<<endl;}
         break;}

system("PAUSE");
return EXIT_SUCCESS;}


bool checkleap(int year)
{if(year%4=0 && year%100!=0 || year%100=0 && year%400=0)
return true;
return false;}

I'm only getting that error in line 55, where I think you're confusing "=" with "==". Take a look at those and report back.

if(year%4==0 && year%100!==0 || year%100==0 && year%400==0)
return true;
return false;}

I was using the assignment operator by mistake there, but am now faced with a new error: expected primary expression before '=' token.

Fixed it! !== is incorrect syntax. I just needed to remove the equality symbol.

Thank you so much for your help, sir, it is much appreciated.

:)

Glad to assist.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.