# lab 6.cpp - C Program Test.cpp Course CSE1311 Assignment...

• Lab Report
• 3

This preview shows pages 1–3. Sign up to view the full content.

// C++ Program Test.cpp // Course CSE1311 // Assignment #: Lab 6 // Due Date: March 3, 2016 // Purpose: /* Make use of multiple Functions Use menus to select different Functions. */ #include <iostream> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; void prime(int n) // function 1. Prime Numbers { cout<< "These are the prime numbers less than "<< n<< endl; for (int i=2; i<=n;i++) { for (int j=2;j<i;j++) { if (i%j==0) break; else if(i==j+1) cout<< i<< endl; } } cout<< "\n========================================================\n"; } void coins(int n) // function 2. Weighted Coins { double cointoss, seed; double tails, heads, count, avg; count=0; seed = time(0); srand(seed); while (count<n) { cointoss= rand ()% 100+1; if (cointoss<=60) { heads++; } else { tails++; } count++; } avg = (heads/n)*100; cout<< "---> The amount of heads = "<< heads<< endl; cout<< "---> The amount of tail = "<< tails<< endl; cout<< "---> The percentage of heads flipped is = "; printf("%.2lf ", avg); cout << "%" << endl; cout<< "\n========================================================\n"; } void evenOdd (int n) // function 3. Even or Odd

This preview has intentionally blurred sections. Sign up to view the full version.

{ n=n%2; if (n==0) { cout<< "***THE VALUE IS EVEN***"<< endl;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<< "\n========================================================\n"; } else { cout<< "***THE VALUE IS ODD***"<< endl; cout<< "\n========================================================\n"; } } int main() { int choice, n, value, num; char input; cout<< "Do you want to continue (Y/N)"<< endl; cin>> input; while ( input=='Y' || input=='y' ) { cout<< "1. Prime Numbers \t 2. Weighted Coins \t 3. Even or Odd\n" << "Type in 1, 2, 3 to choose a function:"<< endl; cin >> choice; switch (choice) { case 1: cout<< "WHICH VALUE DO YOU WANT THE PRIME NUMBERS LESS THAN?" << endl; cin>> n; prime(n); // function 1 break; case 2: cout<< "HOW MANY TOSSES DO YOU WANT TO PERFORM?"<< endl; cin>> n; coins(n); // function 2 break; case 3: cout<< "WHAT IS YOUR VALUE? "<< endl; cin>> n; evenOdd(n); // function 3 break; default: cout<< "***BAD CODE***" << endl; cout<< "\n========================================================\n"; } cout << "Do you want to continue ? (Y/N)" << endl; cin >> input; } cin.get(); // stops the program to view the output until you type any character return 0; }...
View Full Document

• Spring '15
• Prime number, endl, cout

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern