Showing posts with label else if nested if. Show all posts
Showing posts with label else if nested if. Show all posts

Sunday, March 1, 2015

Write a program that calculates and prints the product of the odd integers from 1 to 15

#include <iostream>
#include <stdlib>

int main()
{
      // Variable declarations.
      int product = 1;

      for( int i = 0; i <= 7; i++)
      {
             product *= 2 * i + 1;
      }

      cout << "Product is: " << product << endl;

      system("PAUSE");
      return 0;
}


Read More

Thursday, February 12, 2015

C plus plus Program to Find if a given Year is a Leap Year

Leave a Comment
Code:-

#include<iostream>
using namespace std;
void main()
{
int year;
cout<<"Enter a year to check leap year =  ";
cin>>year;
if(year%4==0&&year%400==0)
{
cout<<"The year is a leap year (it has 366 days)."<<endl;
}
else
cout<<"The year is not a leap year (it has 365 days)"<<endl;
}

Output;-


Read More

Thursday, February 5, 2015

Commission Program using nested if

Leave a Comment
/*
Using the following chart, write an if/else if statement that assigns
.10, .15, or .20 to commission, depending on the value in sales.
Sales Commission Rate
Up to $10,000 10%
$10,000 to $15,000 15%
Over $15,000 20%
*/
#include<iostream>
using namespace std;
void main()
{
int sales =0;
cout<<"Enter Sales = ";
cin>>sales;
if(sales<10000)
{
cout<<"Commission Rate is == 10%"<<endl;
}
else if(sales>=10000||sales<15000)
{
cout<<"Commission Rate is == 15%"<<endl;
}
else
{
cout<<"Commission Rate is == 20"<<endl;
}
}
Read More

write an if/else statement that assigns 0 to x when y is equal to 10. Otherwise it should assign 1 to x.

Leave a Comment
/*
write an if/else statement that assigns 0 to x when y is equal to 10. Otherwise it should assign 1 to x.
*/
#include<iostream>
using namespace std;
void main()
{
    int x=0,y=0;
    cout<<"Enter the value of x = ";
    cin>>x;
    cout<<"Enter the value of y = ";
    cin>>y;
    if(y==10)
    {
        x=0;
    }
    else{
    x=1;
    }
    cout<<"The value of x = "<<x<<endl;
    cout<<"The value of y = "<<y<<endl;
}
Read More

Write an if statement that assigns 100 to x when y is equal to 0.

Leave a Comment
/*
Write an if statement that assigns 100 to x when y is equal to 0.
*/


Code :

#include<iostream>
using namespace std;
void main()
{
    int x=0,y=0;
    cout<<"Enter the value of x = ";
    cin>>x;
    cout<<"Enter the value of y = ";
    cin>>y;
    if(y==0)
    {
        x=100;
    }
    cout<<"The value of x = "<<x<<endl;
    cout<<"The value of y = "<<y<<endl;
}
Read More