Jump to content

easy_code

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by easy_code

  1. here are the solutions:

    1 and 2: line #33 & 53 }while(again = 'y');    if(a=b)

    there is a logical error.

    the = will alaways return  true.

    this is because the compiler sees it as an assignment.

    the = should be == to make it a comparison.

    3: line #22 randChar = rand()%4;

    the range of comparible characters is not a,b,c

    instead it has a range of: null, ?, ?, ?

    to fix this add 'a' or 97 to get it in the range of a-d

    4: line #2  #include <ctime>

    This is not the error but a hint.

    You can write a line that initializes the random number

    based on the system time.

    srand(time(0));

    This allows you to be able to run the app without having it

    choose the same random number every time.

    Congrats to: sablefoxx and TheWarden for finding errors 1, 2, and 3

    Here is the Next Challenge:

    Wrte a Program that

    1. an integer is inputed

    2. the number is converted to binary

    3. output the binary number

    Bonus: make it also do Octal and/or Hexadecimal

  2. sablefoxx's found some of the errors  on lines 33,and 54

    33: }while(again = 'y');

    53: if(a=b)   //it waws actually on 53

    someone could post what these errors are

    there are still 2 more errors.

    i could post the errors you want.

  3. sablefoxx what compiler are you using?

    I'm using Microsoft Visual Studio 2005

    and I don't see any warnings or errors

    this is not one of the errors but should fix some of the strict warnings your compiler is giving you

    try  replacing  line 25:  if(compare(myNum, randNum) && compare(myChar, randChar))

    with:  if(compare<int>(myNum, randNum) && compare<char>(myChar, randChar)) 

  4. is this the code that you want?

    only runtime errors and not syntax errors

    #include &lt;iostream&gt;
    #include &lt;ctime&gt;
    using namespace std;
    
    char get_Char();
    int get_Int();
    template &lt;class Type&gt;
    bool compare(Type,Type);
    
    int main(){
        int myNum, randNum;
        char myChar, randChar;
        char again;
        
        cout&lt;&lt;"  Welcome to the Awesome Game  n";
            
        do{
            cout&lt;&lt;"*******************************n";
            myChar = get_Char();
            myNum = get_Int();
            
            randChar = rand()%4;
            randNum = rand()%3;
            
            if(compare&lt;int&gt;(myNum, randNum) &amp;&amp; compare&lt;char&gt;(myChar, randChar))
                cout&lt;&lt;"You  Winn";
            else
                cout&lt;&lt;"You Loosen";
    
            cout &lt;&lt; "do you want to play again(y/n)? ";
            cin &gt;&gt; again;
    
        }while(again = 'y');  
    
        cout&lt;&lt;"*******************************n"
            &lt;&lt;"Thanks for Playingn";
        return 0;
    }
    
    char get_Char(){
        char temp;
        cout&lt;&lt;"enter a character(a-d): ";
        cin&gt;&gt;temp;
        return temp;
    }
    int get_Int(){
        int temp;
        cout&lt;&lt;"enter an integer(1-3): ";
        cin&gt;&gt;temp;
        return temp;
    }
    template &lt;class Type&gt;
    bool compare(Type a,Type b){
        if(a=b)
            return true;
        else
            return false;
    }

    edited after sablefoxx's comment #55  and my comment #56

×
×
  • Create New...