easy_code
-
Posts
5 -
Joined
-
Last visited
Posts posted by easy_code
-
-
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.
-
Your compiler did find some of the errors,
and i don't think i can hide them from you compiler.
Try fixing the errors and look for the rest of the errors.
Also post as you fix errors.
-
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))
-
is this the code that you want?
only runtime errors and not syntax errors
#include <iostream> #include <ctime> using namespace std; char get_Char(); int get_Int(); template <class Type> bool compare(Type,Type); int main(){ int myNum, randNum; char myChar, randChar; char again; cout<<" Welcome to the Awesome Game n"; do{ cout<<"*******************************n"; myChar = get_Char(); myNum = get_Int(); randChar = rand()%4; randNum = rand()%3; if(compare<int>(myNum, randNum) && compare<char>(myChar, randChar)) cout<<"You Winn"; else cout<<"You Loosen"; cout << "do you want to play again(y/n)? "; cin >> again; }while(again = 'y'); cout<<"*******************************n" <<"Thanks for Playingn"; return 0; } char get_Char(){ char temp; cout<<"enter a character(a-d): "; cin>>temp; return temp; } int get_Int(){ int temp; cout<<"enter an integer(1-3): "; cin>>temp; return temp; } template <class Type> bool compare(Type a,Type b){ if(a=b) return true; else return false; }
edited after sablefoxx's comment #55 and my comment #56
Coding challenge
in Applications & Coding
Posted
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