|
-
July 22nd, 2008, 09:21 PM
#1
Critique What I've Relearned?
So, now I've gone through and relearned a lot of basic stuff. There's a lot more to learn, but I'd like to gauge my progress so far.
Here's what I've relearned:
Variables, I/O, Conditional Statements, Loops, and Functions
And here is a little program I made that includes all of those things. I'm looking for critiques on everything from redundancy checks to nit picking style and technique. If you think I can learn from your comments, and they aren't phrased in a brutal way, then please post.
Code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int counter=1;
int instructions (char res1)
{
string res2;
int inst_loop, inst=1;
if (res1=='y')
{
while (inst==1)
{
cout << "The instructions are simple:"
<< endl << endl
<< "When the program prompts you, follow its instructions..."
<< endl
<< "Choosing up (u) will make the count increase."
<< endl
<< "Choosing down (d) will make the count decrease."
<< endl
<< "When Counter reaches 0, it will terminate."
<< endl << endl;
cout << "Type \"ready\" to continue\n";
cin >> res2;
if (res2=="ready")
{
inst=0;
cout << "Have fun!\n";
}
else
{
cout << "Let's try again...\n\n";
}
}
inst_loop=0;
}
else if (res1=='n')
{
cout << "On with Counter then!\n\n";
inst=0;
inst_loop=0;
}
else
{
cout << "Not an acceptable response, try again.\n(y/n)";
cin >> res1;
inst_loop=1;
}
return inst_loop;
}
int counters()
{
int program=1;
char res3;
cout << "Counter is: "<< counter << endl
<< "Up or down? (u/d)" << endl;
cin >> res3;
if (res3=='u')
{
counter++;
}
else if (res3=='d')
{
counter--;
}
else
{
cout << "Incorrect response, try again...\n";
}
if (counter<=0)
{
program=0;
cout << "Counter has reached 0, Thank you for playing!\n";
system ("PAUSE");
}
else
{
program=1;
}
return program;
}
int main ()
{
int program=1, inst_loop=1;
char res1;
string res2;
cout << "Welcome to Counter!"
<< endl
<< "Would you like to read the instructions?(y/n)\n";
cin >> res1;
while (inst_loop==1)
{
inst_loop = instructions(res1);
}
while (program==1)
{
program = counters();
}
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|