Alumnio

Submitted by: Submitted by

Views: 96

Words: 977

Pages: 4

Category: Science and Technology

Date Submitted: 12/10/2013 06:01 PM

Report This Essay

If statement

Create a program which will allow the user to log in...

If the user types in the correct password, he will be logged in; If it's a wrong password, it will not let him log in...

#include<iostream>

using namespace std;

int main()

{

char answer[10];

cout<<"Please enter the password: ";

cin>>answer;

cin.ignore();

if (answer[10] == 'wrox') {

cout<<"You have successfully logged in";

}

else {

cout<<"Wrong Password";

}

cin.get();

}

If else statement

if gender is male and grade is 70 and above, display "good boy";

if gender is female and grade is 70 above, display "good girl";

but if grade is below 70 regardless of gender, display "bad child";

#include<iostream.h>

#include<conio.h>

char grade;

main()

{

int grade;

cout<<"gender:";

cin>>gender;

cout<<"grade:";

cin>>grade;

if(gender=='M'||'m')

if(grade>=70)

cout<<"goodboy";

if(gender=='F'||'f')

if(grade>=70)

cout<<"\n goodgirl";

else

cout<<"\n badchild";

getch();

return 0;

}

For Loop

Create a program that accepts 5 integers. Calculate and display 

the sum of 5 input integers and the other is make a program that accepts 5 characters and 

display the number of digits among the 5 input characters.

#include<iostream.h>

using namespace std;

int main()

{

char str[6]; //no of characters in a c style array =subscript-1

cin>>str;

for(int i=0;i<5;i++)

{

if(str[i]>='0' && str[i]<='9') //check if str[i] is a digit or not

cout<<str[i]<<" is a digit."<<endl;

}

return 0;

}

While Loop

Create a program that will ask a user to enter number between 1 and 20. If number is greater than 20 the first functioned which is input Information must loop until the number between 1 and 20 is entered. 

#include <iostream.h>

using namespace std;

int funcInputFormation(int...

More like this