Skip to content

Instantly share code, notes, and snippets.

View Elsayegh's full-sized avatar

Wael Elsayegh Elsayegh

  • McCarthy Taylor Systems Ltd
  • Gloucester, United Kingdom
View GitHub Profile
@Elsayegh
Elsayegh / sumRandomNumbers.cpp
Last active July 27, 2018 14:32
C++ Programming Challenges
/*Program display two random numbers and user enter the correct answer, if answer is right congratulations is printed ,
if not wrong answer and correct answer printed*/
int randomNum1, randumNum2;
int userTotal, computerTotal;
int seed = time(0);
srand(seed);
randomNum1 = 1 + rand() % 100;
randumNum2 = 1 + rand() % 100;
@Elsayegh
Elsayegh / changeCountingGame.cpp
Last active July 27, 2018 14:26
C++ Challenge
/*Change counting game that gets the user to enter the number of coins required to make exactly one dollar,
program should ask the user to enter the number of pennies, nickles, dimes, and quarters that equal to one dolar.
if the numbers equal one dollar, the program should congratulate the user. the program should display a message if the number
less or bigger than one dollar */
int penny, nickel, dime, quarter;
double total = 0;
cout << "Enter the number of pennies: ";
cin >> penny;
cout << "enter the number of nickeles: ";
/* A gym currently charges $2500 per year for membership and
it has announced it will increase its membership fees by 4% each year, for the next six years. write a program that uses a loop that display
the projected rates for the next six years*/
double fees = 2500.00, increasePercent = 0.04;
int years = 6;
for (int i = 1; i <= years; i++) {
fees = fees + (fees * increasePercent);
cout << "fees will be $ " << fees << " at the year " << i << "\n" << endl;
}
/* Running on a particular treadmill you burn 3.9 calories per min. write a program that ises a loop to display the number of burned
calories after running 10, 15, 20, 25, 30 minutes. */
float calPerMin = 3.9, totalCal = 0;
int runnedTime = 30;
for (int time = 10; time <= runnedTime; time = time + 5) {
totalCal = calPerMin * time;
cout << "Burned calories after running " << time << " Mins is: " << totalCal << endl;
}
@Elsayegh
Elsayegh / oceanLevelRising.cpp
Created July 27, 2018 14:34
C++ Challenges
/* Assuming the ocean's level is currently rising at about 1.5mm per year,
write a program that displays a table showing the number of mm that the ocean will have risen each ear for the next 25 years.*/
float riseLvl = 1.5;
int years = 25;
float nmNumber = 0;
for (int i = 1; i <= years; i++) {
nmNumber += riseLvl;
cout << "The number of mm that ocean will rise at the year " << i << " is : " << nmNumber << endl;
}
@Elsayegh
Elsayegh / sumOfValues.cpp
Created July 27, 2018 14:35
C++ Challenge
/*Write a program that asks the user for a positive integer value.
The program should use a loop to get the sum of all the integers from 1 up to the number entered.
For example, if the user enters 50, the loop will sum 1+2+3+...+50.
Input validation: Do not accept negative numbers.*/
int n, sum = 0, total = 0;
cout << "Enter the number : " << endl;
cin >> n;
for (int i = 1; i <= n; i++) {
sum += i;
/*The distance a vehicle travels can be calculated as follows: distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles.
Write a program that asks the user for the speed of a vehicle and how many hours it has traveled.
The program should then use a loop to display the distance the vehicle traveled for each hour of that time. */
int speed, time;
cout << "what was the speed while driving? "<< endl;
cin >> speed;
cout << "time travelled" << endl;
cin >> time;
@Elsayegh
Elsayegh / calculateSalary.cpp
Last active July 27, 2018 14:40
C++ Challenge
/*Write a program that calculates how much a person would earn over a period of time if his or her salary is one penny the first day,
two pennies the second day, and continues to double each day. The program should ask the user for the number of days.
Display a table showing how much the salary was for each day, and then show the total pay at the end of the period.
The outputs should be displayed in a dollar amount, not the number of pennies*/
int workingDays, salary = 1;
cout << "how many days you work? ";
cin >> workingDays;
for (int i = 1; i <= workingDays; i++) {
cout << "Working " << i << " days salary is: " << salary << endl;
/* Write a program that calculates the occupancy rate for a hotel. The program should start by asking user how many floors the hotel has.
A loop should then iterate once for each floor. In each iteration, the loop should ask the user for the number of rooms on the floor
and how many of them are occupied. After all the iterations, the program should display how many rooms the hotel has,
how many of them are occupied, how many are unoccupied, and the percentage of rooms that are occupied.
The percentage may be calculated by dividing the number of rooms occupied by the number of rooms.
Input validation: Do not accept a value less than 1 for the number of floors.
Do not accept a number less than 10 for the number of rooms on a floor.
NOTE: It is traditional that most hotels do not have 13th floor. The loop in this program should skip the entire 13th iteration. */
#include <iostream>
/*Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years.
The program should first ask for the number of years. The outer loop will iterate once for each year.
The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of
rainfall for that month. After all the iterations, the program should display the number of months, the total inches of rainfall
and the average rainfall per month for the entire period.Input validation: Do not accept a number less than 1 for the number of years.
Do not accept negative numbers for the monthly rainfall.*/
#include <iostream>
#include <conio.h>
#include <ctime>