CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | Be a CE Ambassador! | Forgot password? | Sponsor CE | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  #1 (permalink)
Old 24th August 2008, 08:40 PM
Good Administrator
 
The_Big_K's Avatar
 
I'm a Crazy Electrical Engineer
Join Date: 26th November 2005
Location: Terra-Firma
Posts: 4,996
Send a message via Yahoo to The_Big_K
Thumbs up C ++ Programing Challenge: Complete the code

Puzzle Source: Cprogramming.com: C++ Programming Challenge - Guessing Game Challenge

The following program will act as a guessing game in which the user has eight tries to guess a randomly generated number. The program will tell the user each time whether he guessed high or low:
Code:
#include <stdlib.h>
#include <iostream>
  using namespace std;  int main()
{
int number=rand()___; 
int
guess=-1;
int trycount=0;
while(guess__number __ trycount<8)
{

cout__"Please enter a guess: ";
cin__guess;
__(guess_number)

cout<<"Too low"<<endl;
 __(guess_number)

cout<<"Too high"<<endl;
_______________;
_

if(guess==number)
cout<<"You guessed the number";
____

cout<<"Sorry, the number was: "<<_____;
______
0;
Those who want to scratch your brain and improve your C++ programming skills - discuss the problems.

Those who need spoon feeding, get the solution at the puzzle source.
The_Big_K is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 26th August 2008, 09:26 PM
Good Administrator
 
The_Big_K's Avatar
 
I'm a Crazy Electrical Engineer
Join Date: 26th November 2005
Location: Terra-Firma
Posts: 4,996
Send a message via Yahoo to The_Big_K
Default Re: C ++ Programing Challenge: Complete the code

I sit and wonder why we don't have a code cracker in our 18,000+ engineers' squad.
The_Big_K is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 26th August 2008, 11:17 PM
CE - Regular Member
 
I'm a Crazy Electronics and Communication Engineer
Join Date: 19th March 2007
Location: Jeddah, Saudi Arabia
Posts: 72
Send a message via AIM to bayazidahmed Send a message via MSN to bayazidahmed Send a message via Yahoo to bayazidahmed
Default Re: C ++ Programing Challenge: Complete the code

Quote:
Originally Posted by The_Big_K View Post
I sit and wonder why we don't have a code cracker in our 18,000+ engineers' squad.
Naah! Again too easy.
bayazidahmed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 26th August 2008, 11:45 PM
Good Administrator
 
The_Big_K's Avatar
 
I'm a Crazy Electrical Engineer
Join Date: 26th November 2005
Location: Terra-Firma
Posts: 4,996
Send a message via Yahoo to The_Big_K
Default Re: C ++ Programing Challenge: Complete the code

Ok, bayazidahmed - how about posting the solution and proving your point?
The_Big_K is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)
Old 27th August 2008, 01:02 AM
CE - Regular Member
 
I'm a Crazy Electronics and Communication Engineer
Join Date: 19th March 2007
Location: Jeddah, Saudi Arabia
Posts: 72
Send a message via AIM to bayazidahmed Send a message via MSN to bayazidahmed Send a message via Yahoo to bayazidahmed
Default Re: C ++ Programing Challenge: Complete the code

Quote:
Originally Posted by The_Big_K View Post
Ok, bayazidahmed - how about posting the solution and proving your point?
Well, If you insist.

#include <stdlib.h>
#include <iostream>
using namespace std; int main()
{
int number=rand() * 1; /*this blank could be used to scale the number, if we give it as * 1, the max number could be upto STD_MAX defined in stdlib.h which is usually 32767*/
int
guess=-1;
int trycount=0;
while(guess != number && trycount<8)
{

cout<<"Please enter a guess: ";
cin>>guess;
if(guess<number)

cout<<"Too low"<<endl;
if(guess>number) // here else if can also come in place of if

cout<<"Too high"<<endl;
trycount++;
}

if(guess==number)
cout<<"You guessed the number";
else

cout<<"Sorry, the number was: "<<number;
return
0;
}//you missed this bracket
bayazidahmed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)
Old 27th August 2008, 01:02 PM
CE - Addict
 
friendster7's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 4th February 2008
Location: india,karnataka
Posts: 386
Send a message via Yahoo to friendster7
Default Re: C ++ Programing Challenge: Complete the code

Quote:
Originally Posted by bayazidahmed View Post
Well, If you insist.

#include <stdlib.h>
#include <iostream>
using namespace std; int main()
{
int number=rand() * 1; /*this blank could be used to scale the number, if we give it as * 1, the max number could be upto STD_MAX defined in stdlib.h which is usually 32767*/
int //error in this line it must be int guess=-1;
guess=-1;

int trycount=0;
while(guess != number && trycount<8)
{

cout<<"Please enter a guess: ";
cin>>guess;
if(guess<number)

cout<<"Too low"<<endl;
if(guess>number) // here else if can also come in place of if

cout<<"Too high"<<endl;
trycount++;
}

if(guess==number)
cout<<"You guessed the number";
else

cout<<"Sorry, the number was: "<<number;
return
0;
}//you missed this bracket
ur code would not give a result.
__________________
Vinay Is Cool..

ha ha ha
friendster7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)
Old 27th August 2008, 04:13 PM
CE - Regular Member
 
I'm a Crazy Electronics and Communication Engineer
Join Date: 19th March 2007
Location: Jeddah, Saudi Arabia
Posts: 72
Send a message via AIM to bayazidahmed Send a message via MSN to bayazidahmed Send a message via Yahoo to bayazidahmed
Default Re: C ++ Programing Challenge: Complete the code

Quote:
Originally Posted by friendster7 View Post
ur code would not give a result.

Too bad, you should have tried compiling and posted your comments. It works perfectly fine for me.

The syntax error you have pointed out will not come in any compiler.

For your information, a single C/C++ statement can be spanned on multiple lines. The statement ends with a ; only.
So, there is nothing wrong in writing
int guess = -1 as
int
guess=-1
OR
int



guess=-1
OR
int
guess
=-1
OR
int
guess
=
-1
bayazidahmed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)
Old 27th August 2008, 07:14 PM
CE - Apprentice
 
I'm a Crazy Computer Engineer
Join Date: 24th July 2008
Posts: 46
Default Re: C ++ Programing Challenge: Complete the code

calm down ahmed
niraj.kumar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)
Old 27th August 2008, 07:29 PM
CE - Regular Member
 
I'm a Crazy Electronics and Communication Engineer
Join Date: 19th March 2007
Location: Jeddah, Saudi Arabia
Posts: 72
Send a message via AIM to bayazidahmed Send a message via MSN to bayazidahmed Send a message via Yahoo to bayazidahmed
Default Re: C ++ Programing Challenge: Complete the code

Quote:
Originally Posted by niraj.kumar View Post
calm down ahmed
Me? No worries. I was just explaining...
bayazidahmed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 10:26 PM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger