[Solved] Warning driving me crazy...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

[Solved] Warning driving me crazy...

Post by zodiac976 »

I decided to work on my my ATM simulator some more
and I ended up restructuring it using pointers since I
like them now..but this 1 warning is driving me nuts:

warning C4715: 'Account::saveWithdraw' : not all control paths return a value

My function returns the value it is supposed to and I
double checked everything leading to it but I still
can't find out why and I did search this on google.

I believe it has to be something in that function
causing the problem but to me the code looks
just fine......
Last edited by zodiac976 on Thu Jul 02, 2009 6:10 am, edited 1 time in total.
User avatar
ismetteren
Chaos Rift Junior
Chaos Rift Junior
Posts: 276
Joined: Mon Jul 21, 2008 4:13 pm

Re: Warning driving me crazy...

Post by ismetteren »

Have you cheked that there is a return statement inside ALL if-statements, loops, switches, etc. and also one outiside?

Maybe you could post the function?
Image ImageImage Image
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Warning driving me crazy...

Post by zodiac976 »

ismetteren wrote:Have you cheked that there is a return statement inside ALL if-statements, loops, switches, etc. and also one outiside?

Maybe you could post the function?
I am pretty sure it is returning what it is supposed to
but I am more than likely not seeing something....

Don't laugh! this code is like 2 months old, I don't quite
remember what was wrong with it before and I code a
little different now but I just wanted to get the program
to work then I can change some stuff...anywho here is
my masterpiece rofl...

Code: Select all

string Account::saveWithdraw()
{   //Saves the amount of withdraws
	string copyWitStr, tempW, tempAcc, tempPass;
	double confWit, tempWit, tempBal;
	bool loopChk = true;
	char nextChar;
	static double newWit = 0.0;

	ifstream file1("Buffer.txt");
			file1 >> tempAcc;
			file1 >> tempPass;
			file1 >> tempBal;
	file1.close();

	while(loopChk == true)
	{
		cls();
		cout << "               Withdraw\n"
			 << "--------------------------------------\n";
		cout << "Please enter the amount to withdraw: $";
		getline(cin, tempW);

		for(int x = 0; x < int(tempW.length()); ++x)
		{
			nextChar = tempW.at(x);

			if(isalpha(nextChar))
			{
				cout << "\nInvalid amount...please re-enter your amount\n";
				pause();
				loopChk = true;
			}
			else
				loopChk = false;
		}

		if(loopChk == true)
			continue;

		stringstream input2(tempW);
		input2 >> tempWit;

		confWit = tempBal - tempWit;

		if(confWit <= 25.00)
		{
			cout << "\nCannot withdraw anymore money...please deposit money first\n";
			pause();
			continue;
		}
		else
			break;
	}

	if(newWit != 0.0)
		tempWit += newWit;

	newWit = tempWit;
	
	if(newWit < 25.00)
	//Not working for some weird reason "says output is undeclared".
	//stringstream output;
	//output << tempWit;
	//tempW = output.str();

	return tempW;
}
Oh by the way, there is probably more errors that will pop up
when I get that warning fixed and also the commented part
of the code to....
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Warning driving me crazy...

Post by zodiac976 »

Never mind, I figured it out lmao...I am sad, I can't believe
I didn't notice it. I had an if statement without a statement..:cry:

EDIT: I spent hours and hours trying to figure out why............... :oops: :oops:
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Warning driving me crazy...

Post by dandymcgee »

zodiac976 wrote:Never mind, I figured it out lmao...I am sad, I can't believe
I didn't notice it. I had an if statement without a statement..:cry:

EDIT: I spent hours and hours trying to figure out why............... :oops: :oops:
Just make sure you don't mess up "=" and "==". It may seem simple enough, but debugging that mistake has literally taken several hours of my life away.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Warning driving me crazy...

Post by MarauderIIC »

Code: Select all

   if(newWit < 25.00)
   //Not working for some weird reason "says output is undeclared".
   //stringstream output;
   //output << tempWit;
   //tempW = output.str();
Because you don't have braces on your if statement. This means that output is declared if newWit is < 25 and goes out of scope on the next line, because variables declared inside braces become invalid once execution exits the brace (this means that variables declared inside a loop are re-declared on every loop iteration, because execution leaves the braces to check the loop condition).

So what you have is equivalent to

Code: Select all

    if(newWit < 25.00) {
        stringstream output;
    }
    output << tempWit;
    tempW = output.str();
And I'm sure this is not what you meant.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: [Solved] Warning driving me crazy...

Post by zodiac976 »

Yea I decided to just redo the whole project because it's
not doing what I want it to do...so I am taking it slower
this time and maybe it will work out right.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [Solved] Warning driving me crazy...

Post by eatcomics »

Get used to it... Rewrites are something that happen alllll the time... :lol: I rewrote my first blitzbasic game 3 or 4 times...
Image
Scoody
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Fri Feb 06, 2009 2:07 pm

Re: [Solved] Warning driving me crazy...

Post by Scoody »

I hate to burst anyones bubble, but planning the project on paper makes it much easier to go where you want.
That is, not down to the smallest detail, but thorough enough to have something to lead you when you get astray :)
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: [Solved] Warning driving me crazy...

Post by zodiac976 »

Scoody wrote:I hate to burst anyones bubble, but planning the project on paper makes it much easier to go where you want.
That is, not down to the smallest detail, but thorough enough to have something to lead you when you get astray :)
I know I always jump on the computer saying I want to
do this and start throwing it together....a bad habit I
guess.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: [Solved] Warning driving me crazy...

Post by dandymcgee »

Scoody wrote:I hate to burst anyones bubble, but planning the project on paper makes it much easier to go where you want.
That is, not down to the smallest detail, but thorough enough to have something to lead you when you get astray :)
My problem with this is I never actually know where I want to go. I have a hard time coming up with ideas for projects to work on for some reason.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply