#include <iostream>
int main()
{
// naming integers
unsigned int age;
unsigned int ageAdult;
unsigned int ageNotAdult;
unsigned int tillAdult;
unsigned int beenAdult;
// setting integers
ageAdult = 18;
ageNotAdult = 17;
tillAdult = ageAdult - age;
beenAdult = age - ageNotAdult;
// Used to get value for unsigned int age
std::cout << "\nHow old are you, in years? ";
std::cin >> age;
// Used to find criteria to output comment
if (age>=40)
{
if (age<=80)
std::cout << "\nWOAH! You're an old geezer! I hope you can read this text...\nIn case you were wondering, you've been an adult for " << beenAdult << " years!";
else
std::cout << "\nWow! You're over 80 years old! I wonder how much longer you have left...\n...\n...\nNope, you're not dead yet!\nYou've lasted " << beenAdult << " years as an adult!";
}
else
{
if (age<18)
{
std::cout << "\nNot an adult yet...\nOnly " << tillAdult << " more years until you can vote!";
}
else
{
if(age>=18&&age<39)
std::cout << "\nHaven't been underage for " << beenAdult << " years. And you're not even 40 yet!";
else
std::cout << "\nYou're almost 40... haha, old man!";
}
}
return 0;
}
Help for C++ Newbie! (Only 3 days!)
I tried making a little program that will comment on your age.
It also says if you're under 18 how many years until you're an adult and if you're over 18 how many years you've been an adult. When it outputs those numbers, it gives me very big numbers... Can anyone tell me the mistake I'm making?
Thanks in advance,
Devor
[edited by - Devor on August 18, 2002 10:40:42 PM]
tillAdult = ageAdult - age;
beenAdult = age - ageNotAdult;
You are using the variable ''age'' before giving it a value. Put those two lines after the ''std::cin >> age;'' line.
beenAdult = age - ageNotAdult;
You are using the variable ''age'' before giving it a value. Put those two lines after the ''std::cin >> age;'' line.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement