} while (cont = "y");
for this line I get:
invalid conversion from 'const char*' to 'char'
} while (cont = "y");
for this line I get:
invalid conversion from 'const char*' to 'char'
} while (cont == "y");
(:
duh...
Oldest mistake in the book.
Yeah, done that a million of times myself :3
Now it thinks "y" is a pointer (I think).
What error does it cast? And a bit more of the code would be good as well..
Ok, I fixed that but I have another problem.
I have this code (you can skip down to the bold):
#include <iostream>
using namespace std;
int bday;
int bmonth;
int byear;
int cday;
int cmonth;
int cyear;
char cont;
int main()
{
do{
system("cls");
cout<<"What year were you born in? (example: 1994)" << endl;
cin>> byear;
cin.ignore();
system("cls");
cout<<"What month of the year were you born in? Please represent numerically (january: 1 , february: 2 , etc.)" << endl;
cin>> bmonth;
cin.ignore();
system("cls");
cout<<"What day of the month were you born? (example: 10)" << endl;
cin>> bday;
cin.ignore();
system("cls");
cout<<"What year is it currently? (example: 1994)" << endl;
cin>> cyear;
cin.ignore();
system("cls");
cout<<"What month is it currently? Please represent numerically (january: 1 , february: 2 , etc.)" << endl;
cin>> cmonth;
cin.ignore();
system("cls");
cout<<"What day of the month is it currently? (example: 10) \n";
cin>> cday;
cin.ignore();
system("cls");
cout<<"You have been sleeping for: "<< (cyear - byear)/3 <<" years, " << (cmonth - bmonth)/3 <<" months, and "<< (cday - bday)/3 <<" days.\n(Based on 8 hours of sleep a day, days rounded)" << endl;
cout<< "1. Restart" <<endl;
cin>> cont;
cin.ignore();
} while (cont == 1);
}
--------------------------------
Yet, upon entering 1 and hitting return, the program quits. Help?
you could always write it like:
As this will make the while fail if cont == 0 (and so you should write "(0) to exit. (1) to restart" or something similar)Code:} while (cont);
thank you, that is helpful, but what was wrong in the 1st place?
You could also have changed cont from char to int if you wanted to compare it with 1.
As for the error with pointers and char I must admit that I've no idea.
I guess someone more experienced could explain it.
cont is a char variable. "1" is a string, which is implemented as a const char* (also known as a pointer to a character constant). You can't compare a char to a char pointer.
When you switched to a 1 instead of a "1", you were then comparing a char to an int. The character '1' is stored as a character code, and that character code is compared against the character code 1. So if the user types 1 it will be converted to a character code (probably 49) which does not equal 1.
One solution is to use '1' to indicate the character '1' instead of the number 1. Then (cont == '1') will be true if the user types 1.
Another solution is to switch cont to an int variable, which will allow you to compare it to 1 correctly.