I'm a beginner, and i've been trying to make a program that outputs someone's age in years and months, and so far i have this. However, i have no idea why it does not work. Can someone help me?
#include <iostream>
void bad (int x, int y)
{
if (x == 1 && y == 1) {
std::cout << "Ango is " << x << " Year old and " << y << "month old!" << endl;
}
if (x > 1 && y > 1) {
std::cout << "Ango is " << x << " Years old and " << y << "months old!" << endl;
}
if (x == 1 && y > 1) {
std::cout << "Ango is one year old and" << y << "months old!" << endl;
}
if (x > 1 && y == 1) {
std::cout << "Ango is" << x << "years old and one month old!" << endl;
}
}
int main ()
{
cin >> x >> endl;
cin >> y >> endl;
bad (x, y)
return 0;
}
You are just missing some syntactical things. Including the std namespace, a couple missing semi colons, and misuse of the endl feature.
Try this:
#include <iostream>
using namespace std;
void bad(int x, int y)
{
if (x == 1 && y == 1) {
std::cout << "Ango is " << x << " Year old and " << y << " month old!" << endl;
}
if (x > 1 && y > 1) {
std::cout << "Ango is " << x << " Years old and " << y << " months old!" << endl;
}
if (x == 1 && y > 1) {
std::cout << "Ango is one year old and" << y << " months old!" << endl;
}
if (x > 1 && y == 1) {
std::cout << "Ango is" << x << " years old and one month old!" << endl;
}
}
int main()
{
int x, y;
cin >> x;
cin >> y;
bad(x, y);
system("pause");
return 0;
}