#include %26lt;cstdlib%26gt;
#include %26lt;iostream%26gt;
#include %26lt;cmath%26gt;
#include %26lt;ctime%26gt;
using namespace std;
using std::srand;
int main(int argc, char *argv[])
{
float b, n, wa, ga, ra, ta, tries;
cout %26lt;%26lt; "This is slots"%26lt;%26lt;endl;
ta = 1000;
cout %26lt;%26lt; "You have " %26lt;%26lt; ta %26lt;%26lt; " tokens" %26lt;%26lt;endl;
n = 10;
while (n %26gt; 0)
{
cout %26lt;%26lt; "you can play " %26lt;%26lt; n %26lt;%26lt; " times" %26lt;%26lt;endl;
cout %26lt;%26lt; "How much do want to wager:";
cin %26gt;%26gt; wa;
while (wa %26gt; ta)
{
cout %26lt;%26lt; "That is not a valid wager" %26lt;%26lt; endl;
cout %26lt;%26lt; "enter a valid wager:" %26lt;%26lt; endl;
cin %26gt;%26gt; wa;
}
while (wa %26lt;= ta - ta)
{
cout %26lt;%26lt; "That is not a valid wager" %26lt;%26lt; endl;
cout %26lt;%26lt; "enter a valid wager:" %26lt;%26lt; endl;
cin %26gt;%26gt; wa;
}
Shortening this C++ program?
since the two while conditions do the same thing, combine them into one condition:
while(wa %26gt; ta || wa %26lt;=ta-ta)
{
cout %26lt;%26lt; "that is not a valid wager." %26lt;%26lt;endl;
cout%26lt;%26lt; "Enter a valid wager."%26lt;%26lt;endl;
cin %26gt;%26gt;wa;
}
And then combine your other conditions:
if(ga %26lt; 1 || ga %26gt; 10)
{
cout %26lt;%26lt;"That is not between 1 and 10" %26lt;%26lt;endl;
cout %26lt;%26lt;"Enter a value between 1 and 10" %26lt;%26lt;endl;
cin %26gt;%26gt; ga;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment