Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-17-2012, 08:20 PM   PM User | #1
pbracing33b
New Coder

 
Join Date: Mar 2012
Posts: 70
Thanks: 6
Thanked 0 Times in 0 Posts
pbracing33b is an unknown quantity at this point
Strange issue with a do_while loop!C++

I have this issue where my program runs fine except that it iterates the number like is should but immediately after that number I get this"5AFEED48" This is a guessing game where the user enters a number and the while loop keeps track of how many guesses have been attempted. So my code works fine except I don't know why I am getting this" guess #15AFEED48, guess #25AFEED48,
guess #35AFEED48, and so on! So I can see that it is keeping track but why is it giving me all the extra stuff? And what does it mean?

Thanks.
pbracing33b is offline   Reply With Quote
Old 10-17-2012, 09:34 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
The problem is on line 15, that semicolon shouldn't be there...

Just kidding, seriously though we need to see some code in order to answer your question.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 10-18-2012, 12:11 AM   PM User | #3
pbracing33b
New Coder

 
Join Date: Mar 2012
Posts: 70
Thanks: 6
Thanked 0 Times in 0 Posts
pbracing33b is an unknown quantity at this point
Quote:
Originally Posted by oracleguy View Post
The problem is on line 15, that semicolon shouldn't be there...

Just kidding, seriously though we need to see some code in order to answer your question.
Code:

#include <iostream>
#include <cstdlib>   // rand and srand
#include <ctime>     // For the time function

using namespace std;

int main()
{
	int random;  
	int guess = 0;
	int userInput = 0;
	srand(time(NULL));
	random = rand() % 100 + 1;
		
	  //Input Section
			cout<<"I am thinking of a number from 1 - 100??\n";
			
	
	do
	  {
			
			cout<<"What is my number?";
			cin>>userInput;
			guess++;

		if (userInput == random)
		{
			cout<<"You win! \n\n";
			system("pause");
			return 0;
		}
				
		else if (userInput < random)
		{
				
			cout<<"Guess #"<<guess<<cout<<"is too low \n\n";
			
		}
		else if (userInput > random)
		{
						
			cout<<"Guess #"<<guess<<cout<<"is too high \n\n";
				
		}	
	  }
	  while(userInput != random);
	  
	  system("pause");
	  return 0;
}
pbracing33b is offline   Reply With Quote
Old 10-18-2012, 07:21 PM   PM User | #4
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Oh easy. The lines where you are printing out the response you are also printing out cout which is just printing the memory address of cout.
Code:
cout<<"Guess #"<<guess<<cout<<"is too low \n\n";
Get rid of that and it will work fine.

Code:
cout<<"Guess #"<<guess<<"is too low \n\n";
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 10-18-2012, 09:29 PM   PM User | #5
pbracing33b
New Coder

 
Join Date: Mar 2012
Posts: 70
Thanks: 6
Thanked 0 Times in 0 Posts
pbracing33b is an unknown quantity at this point
Oh my I didn't even see that or realize that I was doing that. I have no idea why I put a cout statement there, must of had a brain fart or something, cause I never do that typically, I didn't even realize that I typed it there. I just kept looking at the logics of things instead of the syntax.

Thanks Oracle!
pbracing33b is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:59 PM.


Advertisement
Log in to turn off these ads.