-
Tutorial #2 issue
Hey everyone I posted this the last timei n the wrong forum :o but any who I altered TuTorial #2 the imput age one and it wont print my answer. I tried something some one pointed out in the other post (for got I went to the Prograsming for windows section) and his suggestion dident work. Here it is. Beaware I am a C++ newb lol
Code:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please imput your age: ";
cin>> age;
cin.ignore();
if ( age= 13> 49) {
cout <<"Your Young!\n";
}
else if ( age= 1> 12) {
cout <<"You are really young!\n";
}
else if ( age= 50> 84) {
cout <<"Your getting Old!\n";
}
else if ( age= 85> 99) {
cout <<"Your getting real old!\n";
}
else if (age= 100> 103) {
cout <<"Damn your still alive!\n";
}
else if (age= 104> 10000 ) {
cout <<"Your Dead get over it!\n";
}
cin.get();
cin.ignore();
}
-
Code:
if ( age= 13> 49) {
cout <<"Your Young!\n";
}
this doesn't make much sence
try:
Code:
if (age <= 13) {
cout << "your young!\n";
}
do the same for every one
EDIT:
o nvm i see what you are trying to do
Code:
if( age >= 1 && age <= 12)
{
cout << "You are really young" << endl;
}
if(age >= 13 && age <= 49)
{
cout << "You are young" << endl;
}
if(age >= 50 && age <= 84)
{
cout << "you are getting old" << endl;
}
if(age >= 85 && age <= 99)
{
cout << "You are getting realy old" << endl;
}
if(age >= 100 && age <= 103)
{
cout << "dam you are still alive" << endl;
}
if(age >= 104)
{
cout << "You are dead ge over it" << endl;
}
-
sweet I got it to work now. When I added the <<end1; it erroed but I removed that and kept the age >= in and it worked. Thanks alot :)
EDIT: how would I make it so it keeps looping after entering the number and getting the result? I tried but it dident do anything.
-
try
end; (end small case L not 1)
and its return 0;
for looping
you can put all the code in a while loop
so it would be something like
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int a = 1;
while (a == 1)
{
// all the code
}
// this will keep looping untill the user closes the program
}
or what he said below it makes more sence mine is just shorted.
-
ya mean with a while loop?
Code:
#include <iostream>
using namespace std;
int main()
{
int age;
char exit;
do
{
cout<<"Please input your age: ";
cin>> age;
cin.ignore();
if( age >= 1 && age <= 12)
{
cout << "You are really young" << endl;
}
if(age >= 13 && age <= 49)
{
cout << "You are young" << endl;
}
if(age >= 50 && age <= 84)
{
cout << "you are getting old" << endl;
}
if(age >= 85 && age <= 99)
{
cout << "You are getting realy old" << endl;
}
if(age >= 100 && age <= 103)
{
cout << "dam you are still alive" << endl;
}
if(age >= 104)
{
cout << "You are dead ge over it" << endl;
}
cin.get();
cin.ignore();
cout << "Exit Y/N?";
cin >> exit;
}while(exit != 'y' || exit != 'Y');
}
-
-
Also, just a helpful tip:
Code:
int x = 5;
if (x=6)
cout << "I love you."<<endl;
It should be noted that this if statement evaluates to true, and will execute. I'm not sure if you really know the difference between = and == just yet, but = assigns the value on the left side of the operator to be that of the right-side operand. == compares two operands without altering them.
-
Cool Will check it out later. Thanks for the help guys. Really apriciate it. Good to have a forum where some one can ask for some help with out getting flamed. :cool: