Feb 11, 2015 at 2:30am Feb 11, 2015 at 2:30am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include <iostream>
#include <time.h>
#include <string>
#include <Windows.h>
using namespace std;
int main()
{
int color;
int loop = 1;
int x = 4;
string color_code;
string simon;
srand(time(NULL));
cout << "simon_says" << endl;
cout << "y = yellow" << endl;
cout << "r = red" << endl;
cout << "g = green" << endl;
cout << "b = blue" << endl;
do
{
do
{
color_code.clear();
color = rand() % 4 + 1;
cout << color << endl;
switch (color)
{
case 1:
color_code = color_code + 'y' ;
break ;
case 2:
color_code = color_code + 'r' ;
break ;
case 3:
color_code = color_code + 'g' ;
break ;
case 4:
color_code = color_code + 'b' ;
break ;
}
loop = loop++;
} while (loop <= x);
cout << color_code << endl;
Sleep(3000);
cout << string(100, '\n' );
cout << "what were the colors (no spaces)" << endl;
cin >> simon;
if (simon == color_code)
{
cout << "correct" << endl;
}
if (simon != color_code)
{
cout << "incorrect" << endl;
}
x = x++;
} while (simon == color_code);
return 0;
}
output
1 2 3 4 5 6 7 8 9 10 11 12
simon_says
y = yellow
r = red
g = green
b = blue
3
3
4
3
g
what were the colors (no spaces)
it should output 4 colors then if u get those 4 correct it generates 5 colors and so on. i had it so it was doing 4 colors and could tel if it was right or wrong then i added the out do while loop for if it was correct and now if only come up with one color but still has the 4 numbers. it come up with the numbers for the colors but it doesnt seem to concatenate the color codes.
Last edited on Feb 11, 2015 at 2:31am Feb 11, 2015 at 2:31am UTC
Feb 11, 2015 at 1:07pm Feb 11, 2015 at 1:07pm UTC
Working version but i still have to add a timer for the guess portion.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include <iostream>
#include <time.h>
#include <string>
#include <Windows.h>
using namespace std;
int main()
{
int color;
int loop = 1;
int x = 4;
string color_code;
string simon;
srand(time(NULL));
cout << "simon_says" << endl;
cout << "y = yellow" << endl;
cout << "r = red" << endl;
cout << "g = green" << endl;
cout << "b = blue" << endl;
do
{
color_code.clear();
loop = 1;
do
{
//color_code.clear();
color = rand() % 4 + 1;
//cout << color << endl;
switch (color)
{
case 1:
color_code = color_code + 'y' ;
break ;
case 2:
color_code = color_code + 'r' ;
break ;
case 3:
color_code = color_code + 'g' ;
break ;
case 4:
color_code = color_code + 'b' ;
break ;
}
loop = loop++;
} while (loop <= x);
cout << color_code << endl;
Sleep(3000);
cout << string(100, '\n' );
cout << "what were the colors (no spaces)" << endl;
cin >> simon;
if (simon == color_code)
{
cout << "correct" << endl;
}
if (simon != color_code)
{
cout << "incorrect" << endl;
}
x = x++;
} while (simon == color_code);
return 0;
}
Last edited on Feb 11, 2015 at 1:29pm Feb 11, 2015 at 1:29pm UTC
Feb 11, 2015 at 5:26pm Feb 11, 2015 at 5:26pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <iostream>
#include <time.h>
#include <string>
#include <windows.h>
#include <sstream>
using namespace std;
class c_guess
{
public :
string choice;
string randomColor;
}guess[100] //Program will crash if it exceeds this number
int main()
{
int color;
int loop = 1;
int x = 4;
int n=0;
int wrong=0;
string color_code;
string mystr;
srand(time(NULL));
cout << "simon_says" << endl;
cout << "y = yellow" << endl;
cout << "r = red" << endl;
cout << "g = green" << endl;
cout << "b = blue" << endl;
do
{
loop = 1;
n=0;
do
{
color = rand() % 4 + 1;
//cout << color << endl;
switch (color)
{
case 1:
color_code = 'y' ;
break ;
case 2:
color_code = 'r' ;
break ;
case 3:
color_code = 'g' ;
break ;
case 4:
color_code = 'b' ;
break ;
}
guess[n].randomColor = color_code;
cout << color_code << endl;
loop++;
n++;
} while (loop <= x);
Sleep(5000);
cout << string(100, '\n' );
cout << "what were the colors (single entry)" << endl;
for (n=0;n<x;n++)
{
getline(cin, mystr);
stringstream(mystr) >> guess[n].choice;
if (guess[n].choice != guess[n].randomColor)
{
cout << "Incorrect" << endl;
wrong++
}
if (guess[n].choice == guess[n].randomColor)
{
cout << "Correct" << endl;
}
}
x++;
} while (wrong<1);
return 0;
}
Your code will say correct only for the last color_code in the loop.
Last edited on Feb 11, 2015 at 5:27pm Feb 11, 2015 at 5:27pm UTC