๐Ÿ”’ Closed Help

Status
Not open for further replies.

XieSmile

Established
#include <iostream>
using namespace std;

int main() {

int num1;

cout << "What is your age? ";
cin >> num1;

if (num1 >= 0 && num1 <= 14) {
cout << "\nChild" << endl;
}
else if (num1 >= 15 && num1 <= 24) {
cout << "\nYouth" << endl;
}
else if (num1 >= 25 && num1 <= 64) {
cout << "\nAdult" << endl;
}
else if (num1 >= 65) {
cout << "\nSenior" << endl;
}
else {
cout << "\nPlease input valid number." << endl;
}

return 0;
}


Yung output po kasi kapag input yung any type of alphabet is Child yung lalabas ano po solution dito na kapag hindi number yung lalabas "Please input valid number"
 
Code:
while(!cin)   // Checks if input is valid type of variable declared, will loops if its false
{
    cout << "That was no integer! Please input valid number: ";
    cin.clear();
    cin.ignore();
    cin >> num1;
}

The rest of conditionals here.
|

Google data type validation.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 280
    Views
  • 2
    Participants
Last reply from:
gantz012

Online now

Members online
972
Guests online
1,259
Total visitors
2,231

Forum statistics

Threads
2,276,188
Posts
28,968,163
Members
1,231,157
Latest member
hassano8787h
Back
Top