+ 1
Why is it not Working
Hello i have here a Code and when i run it the output is totaly wrong. cqn you help me Code : #include <iostream> using namespace std; int main() { int a; int b; int c = a - b; cout << "Enter Your year." << endl; cin >> a; cout << "Enter you Birthday" << endl; cin >> b; cout << "You are "; cout << c; cout << " years old."; return 0; }
7 Answers
+ 2
You try to do a - b at the third line, but they haven't value.
+ 2
Yes, but you do the operation before you put value in them. If you want it work, remove a - b, and after the two cin add: c = a - b.
+ 2
#include <iostream>
using namespace std;
int main()
{
int a;
cin>>a;
if (a>=0 && a<18)
{
cout<<"You Are Young";
}
if (a>=18 && a<30)
{
cout<<"You Are Adult";
}
if (a>=30 && a<100)
{
cout<<"You Are Old";
}
return 0;
}
Created it myself Just Give It A Try. It Works
+ 1
but at the 6 line i have cin to value them
+ 1
Thank you now it works and the next time i know what the problem is :D
+ 1
You're welcome :)
+ 1
The first [c=a-b] is to define ur return value to be an integer..........
you have to put it also at the last cin function, so that u can command the compiler to calculate that for you after receiving ur inputs......