Posts

Showing posts from October, 2020

Stock Market Simulator / Comp. Interest Calculator

 #include <iostream> #include <cmath> using namespace std; int main() {     float a;     float p = 100 0;     float r = .01;     for(int day = 1; day <= 30; day++){         a = p * pow(1+r, day);         cout << day << "  --------  " << a << endl;     } }

Avg age of any no. of ppl while loop

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int age, totalppl = 0, ageTotal = 0;     cout << "Enter First persons age or -1 to exit " << endl;     cin >> age;     while(age!=-1){         ageTotal = age + ageTotal;         totalppl = totalppl + 1; //Important          cout << "Enter next persons age or -1 to exit: " << endl;          cin >> age;     }     cout << "Total People Entered is: " << totalppl << endl;     cout << "Average age is : " << ageTotal/totalppl << endl;     return 0; }

Avg age of any no. of ppl for loop

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int age, totalppl = 0, ageTotal = 0;     cout << "Enter First persons age or -1 to exit " << endl;     cin >> age;     for(totalppl; age!=-1; totalppl++)     {         ageTotal = age + ageTotal;         cout << "Enter next persons age or -1 to exit: " << endl;         cin >> age;     }     cout << "\n\n Total no. of people are : " << totalppl << endl;     cout << "\n Avereage age of all the people is: \n\n " << ageTotal/totalppl;     return 0; }

Random Number

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int x;     cout << time(0); //IMPORTANT     srand(123);     for(x; x<30; x++){         cout << (rand()%31)+15 << endl; //IMPORTANT     } }

Sum of n numbers( n is entered by user).

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int x = 1, n, number, total;     total = 0;     cout << "Enter how many numbers you want to add: " << endl;     cin >> n;     for(x; x<=n; x++){ //Important         cout << "Enter " << x << " number: " << endl;         cin >> number;         total = total + number;     }     cout << total << endl;     return 0; }

Primitive Calculator using C++

 #include <iostream> using namespace std; int main() {     int a, b, Sum, Difference, Multiplication, Division, Op;     cout << "Enter first no. " << endl;     cin >> a;     cout << "Enter second no. " << endl;     cin >> b;     cout << "Choose Operation from below \n Sum \n Difference \n Multiplication \n Division" << endl;     cin >> Op;     if(Op==Sum)     {         cout << "The Sum is " << a + b << endl;     }     else if(Op==Difference)     {         cout << "The difference is " << a -b << endl;     }     else if(Op==Multiplication)     {         cout << "Product is " << a*b << endl;     }     else if(Op==Division)     {   ...