+ 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; }

10th Nov 2016, 8:53 PM
Aquila LP
Aquila LP - avatar
7 Answers
+ 2
You try to do a - b at the third line, but they haven't value.
10th Nov 2016, 9:11 PM
Volts
Volts - avatar
+ 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.
10th Nov 2016, 9:21 PM
Volts
Volts - avatar
+ 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
18th Nov 2016, 7:02 PM
ÇhĂȘtÀñ JĂąwĂ„lĂ«
ÇhĂȘtÀñ JĂąwĂ„lĂ« - avatar
+ 1
but at the 6 line i have cin to value them
10th Nov 2016, 9:17 PM
Aquila LP
Aquila LP - avatar
+ 1
Thank you now it works and the next time i know what the problem is :D
10th Nov 2016, 9:27 PM
Aquila LP
Aquila LP - avatar
+ 1
You're welcome :)
10th Nov 2016, 9:29 PM
Volts
Volts - avatar
+ 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......
11th Nov 2016, 12:41 AM
Alabi Oyewumi Emmanuel
Alabi Oyewumi Emmanuel - avatar