Here's an interesting little scenario. You get challenged to a game of coin toss. Both players pick a sequence of coin toss results (heads or tails). The coin is repeatedly tossed until the sequence for one of the players occurs. The loser pays the winner a dollar. You'd assume that you each have an equal chance of winning. However, using two little "tricks" you can tip the odds in your favour. The first trick is to always choose second. If you can manage this then your strategy is as follows: Your first choice should be the opposite of your opponent's …

Member Avatar
Member Avatar
+0 forum 36

after the 1st iteration the toss is 100 and then the iteration increases toss to 200 and then 300. Why is this happening i want toss to be made only hundred times. PLease help me. #include <iostream> using namespace std; #include <cstdlib> #include<ctime> int toss(void); int main(void) { srand(time(0)); int headcount=0; int tailcount=0; char ht; loop:cout<<"press h for calling out head"<<endl<<"or t for calling out tail"<<'\n'<<"e for exiting game"<<'\n'; cin>>ht; if(ht=='h'||ht=='t') { for(int i=0;i<100;i++) { int k=toss(); if(k==0) { cout<<"heads"<<endl; headcount++; } else { tailcount++; cout<<"tails"<<endl; } } cout<<"the number of heads is "<<headcount<<endl; cout<<"the number of tails is "<<tailcount<<endl; …

Member Avatar
Member Avatar
+0 forum 8

So I am taking C++ at thomas edison state college for a degree. I needed a computer course so I chose C++ instead of PLCs. The reason being is that I used to do some basic coding back in the apple IIe days. I apparently don't have the attention span or interest anymore so I am having issues. Maybe its kids or wife or whatnot. I do understnd it is different progrmming. Now the problem I have is that I cannot figure out how to math it correctly. For instance when I enter 1.88 it gives me the appropriate amount …

Member Avatar
Member Avatar
+0 forum 14

Please take a look at the below code #include <QtCore/QCoreApplication> #include <iostream> int main(int argc, char *argv[]) { using namespace std; double purchaseAmount; double paidAmount; float balance; int change, quarters, dimes, nickels, pennies, tenDollar, fiveDollar; // declare variables cout << "Enter Total purchased amount" << endl; cin >> purchaseAmount; cout << "Enter Total paid amount" << endl; cin >> paidAmount; balance = paidAmount - purchaseAmount ; tenDollar = balance / 10; // calculate the number of Ten Dollars change = tenDollar % 10 ; // calculate the change needed change = balance * 100; quarters = change / 25; // …

Member Avatar
Member Avatar
+0 forum 5

This is the famous counterfeit coin game in C++. # include <iostream> # include <cstring> # include <ctime> # include <cstdlib> # define coinVal 2; using namespace std; void gameInfo(); void generateGame(); void playGame(); int coins, counterfeitCoin; char typeOfCounterfeit; int main() { gameInfo(); generateGame(); } void gameInfo() { cout<<" Enter number coins(max 12) : "; cin>>coins; cout<<" Press (H) for heavy counterfeit and (L) for light : "; cin>>typeOfCounterfeit; } void playGame(int coinTab[]) { cout<<"\n You will get 3 chance to identify the 'bad' coin "; int pan1, pan2, sum1=0, sum2=0, answer; for(int i=0 ; i<3 ; i++) { cout<<"\n …

Member Avatar
Member Avatar
+0 forum 3

The End.