[try Beta version]
Not logged in

 
Please help me I started a program and now i need help

Mar 16, 2008 at 2:22am
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<iostream.h>
#include <math.h>
#include <cstdlib> 
#include <ctime>

#include <cmath>
#include <ctype.h>

using namespace std;
 



void compraing();


 int Myarray [10];                     ///i need help 
    for(int i=0;i<10;i++)            ///
int Myarray[i]=0;                  ///

// int main

int main() 	{ 
   
     int random, guess, dist, numgames, play, turn=0; 
do {
turn=0;
system("cls");
numgames=1;

	
       compraing();

    
    cout<<"Do you want to play again(1 for yes, 2 for no): ";
    cin>>play;
    	numgames=1;
    	if (play==2)
	    	numgames=0;
} while (numgames==1);
    return 0;
   
    }
   
   
   
 ///this is the function 
   
   
    void compraing()
   {int guess,dist,turn,random,numgames;
  
turn=0;
system("cls");

	 srand((unsigned)time(0)); 
     random= (rand()%200) +1;

do {
	turn++;
	 cout<<"What is your guess, between 1 and 200?  ";
	 cin>>guess;
	 dist=random-guess;
     dist=abs(dist);
     cout<<random;


if (dist==0) {
	cout<<"YOU GUESSED IT";
	cout<<endl;
	break; }
else if (dist<=3 && dist>0) {
	cout<<"You are HOT"; 
	cout<<endl; }
else if (dist<=5 && dist>3) {
	cout<<"You are WARM";
	cout<<endl; }
else if (dist<=8 && dist>5) {
	cout<<"You are COOL";
	cout<<endl; }
else if (dist>8) {
	cout<<"You are FREEZING";
	cout<<endl; }
if (turn>=10){
     cout<<"You have lost because you went over your turn limit of 10 turns to guess  /n/n   ";
       break; }
} while (true);              
           


    cout<<"It took you "<<turn<<" guesses to guess the correct number!";
    cout<<endl ;

Myarray[turn-1]=turn;            //my teacher told me to do this
        
    }







The assignment was to make a random generator and you have 10 guesses to get the number.. (i got that part)........ the next part is since you can play again because of the loop i need to make a array of the numbers it took you to try to guess the numbers from lowest to highest.

for example: lets say it took me 10 turns to guess the first time i played
then after because of the loop i played again and it took me 5 turns.... i need to print those numbers in a array format like for example ; 5,10 ......







THANKS FOR YOUR HELP!!!!!!!!
Mar 16, 2008 at 11:47am
Before posting your code, you should make sure it's properly indented. I don't even bother reading it the way it's formatted.

There are three common styles of indenting:

1
2
3
4
5
6
7
8
9
10
11
12
13
if (a > 5) {
  // This is K&R style
}
 
if (a > 5) 
{
  // This is ANSI C++ style
}
 
if (a > 5) 
  {
    // This is GNU style
  }


Find an editor that supports automatic indenting, and let it do it's work.
Topic archived. No new replies allowed.