Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
Loading... 

Thread: how to get names? - C++


Started 2 years, 8 months ago by zandiago
CPP Syntax ( Toggle Plain Text ) #include <iostream> #include <cstdlib> #include <cmath> #include <ctime> using namespace std; int main ( ) { srand ( time ( 0 ) ) ; int randNum = rand ( ) % 100 + 1 ; // Generates random number between 1 and 100 int num = 0 ; int name; //Name of player...
Site: www.daniweb.com - IT Tech Talk  www.daniweb.com - IT Tech Talk - site profile
Forum: C++  C++ - forum profile
Total authors: 3 authors
Total thread posts: 11 posts
Thread activity: no new posts during last week
Domain info for: daniweb.com

Other posts in this thread:

Ancient Dragon replied 2 years, 8 months ago
>>How do I get the program to request for a player's name declare a std::string object to hold the name, then call getline() to get the name from the keyboard. >>How can I keep track of the user's guesses with a counter declare an integer object to be the counter then increment it each time the user makes a guess. >>third question declare int counters for the number of ...

zandiago replied 2 years, 8 months ago
#include <iostream> #include <cstdlib> #include <cmath> #include <ctime> #include <string> using namespace std; int main() { srand(time(0)); int randNum = rand() % 100 + 1; // Generates random number between 1 and 100 int num = 0; int wins = 0; int losses = 0; int tries = 0; string uname; cout <<"Please enter your name...

Narue replied 2 years, 8 months ago
Your conditionals are a little wacky. In particular this one: if (num < randNum) cout <<uname<<""<<"Your number was too low-please try again!"<< endl; { wins = wins ++; break; } I'm reasonably sure you don't realize what it's actually doing, which is always incrementing wins and breaking. A little whitespace and extra braces should show you how the compiler sees this...

zandiago replied 2 years, 8 months ago
cplusplus Syntax ( Toggle Plain Text ) #include <iostream> #include <cstdlib> #include <cmath> #include <ctime> #include <string> using namespace std; int main ( ) { srand ( static_cast<unsigned int> ( time ( 0 ) ) ) ; int randNum = rand ( ) % 100 + 1 ; int num = 0 ; int ...

Ancient Dragon replied 2 years, 8 months ago
line 48 needs to be inside the do loop, probably just above line 34.

zandiago replied 2 years, 8 months ago
ancient dragon-how do i put my source code in tags?

Narue replied 2 years, 8 months ago
>how do i put my source code in tags? Start by being more perceptive. There's a button on the extended editor that adds code tags for you, and the text editor itself has a permanent watermark with instructions on how to use them.

zandiago replied 2 years, 8 months ago
#include <iostream> #include <cstdlib> #include <cmath> #include <ctime> #include <string> using namespace std; int main() { srand ( static_cast<unsigned int> ( time ( 0 ) ) ); int randNum = rand() % 100 + 1; int num = 0; int wins = 0; int losses = 0; int guess=0; string uname; cout<<"Please enter your name: "; getline ( cin, uname ); ...

zandiago replied 2 years, 8 months ago
I have placed the guess++; within the loop and it works, just now gottoa work on the program keeping a tallie as to much much times it prints out "Your number was too high-please try again!"vs "Your number was too low-please try again!".

zandiago replied 2 years, 8 months ago
Got it.....thanks for all assistance-finally figured it all out. not alot of good c++ instructors/professors out there....thanks.

 

Top contributing authors

Name
Posts
zandiago
7
user's latest post:
how to get names? - Page 2 - C++
Published (2007-07-02 05:36:28)
Got it.....thanks for all assistance-finally figured it all out. not alot of good c++ instructors/professors out there....thanks.
Ancient Dragon
2
user's latest post:
how to get names? - C++
Published (2007-07-02 05:36:22)
line 48 needs to be inside the do loop, probably just above line 34.
Narue
2
user's latest post:
how to get names? - C++
Published (2007-07-02 05:36:22)
&gt;how do i put my source code in tags? Start by being more perceptive. There's a button on the extended editor that adds code tags for you, and the text editor itself has a permanent watermark with instructions on how to use them.

Related threads on "www.daniweb.com - IT Tech Talk":

Related threads on other sites:

Thread profile page for "how to get names? - C++" on http://www.daniweb.com. This report page is a snippet summary view from a single thread "how to get names? - C++", located on the Message Board at http://www.daniweb.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity