C++ help!

Started by
18 comments, last by GameDev.net 20 years, 10 months ago
quote:Original post by Jedyte
Or does your code end up malformed by the forum?


By choosing quote or edit on the original message, you can see it''s because they haven''t used the correct tags for the forum.
Advertisement
#include <iostream>using namespace std;int SquareTotal(int toSquare);int main(){        int toSquare;	cout<<"this program will square from 1 to the number you have entered.\n"<<endl;	cout<<"please enter a number:  ";	cin>>toSquare;	if(toSquare <=0)	{ 		cout<<"please enter a non negative, non zero number."<<endl;		cout<<"number:  ";		cin>>toSquare;	}	cout<<"the number you have entered is:  "<<toSquare<<endl;		SquareTotal(toSquare);		cout<<"the total is:  "<<toSquare<<endl;	return 0;}int SquareTotal(int toSquare){	int total=0;	for (int counter =1;counter<=toSquare;counter++)	{		total +=counter*counter;	}	return total;}
quote:please enter a number: 5
the number you have entered is: 5
the total is: 5

toSquare is 5
you print out toSquare
it prints 5

whats the problem?

[edited by - petewood on June 4, 2003 7:04:41 AM]
quote:Original post by Anonymous Poster
*cough homework cough*


Hah, a homework level question would be: A user will input a positive real number greater than or equal to 1, and a period which is greater than 0 and less than (positiveRealNumber - 1). Your program will calculate the square root of all values between from 1 to the positive real number INCLUSIVE, increasing by the period each iteration.

The catcher. Your program must run in at worst O(n log n ) time. Where n is (positiveRealNumber - 1)/period. Fun problem! =)

No non-user-defined functions (Except for non-formatted output) are allowed. In other words, calculate the square roots yourself.

So, if the user input 5.5 as the positiveRealNumber and 0.5 as the period.. you would calculate 1^(.5) + 1.5^(.5) + 2.0^(.5) + 3.0^(.5) ... + 5.5^(.5) and sum the results using a complexity not worse than O(n log n) -> n = 9



[edited by - haro on June 4, 2003 2:25:11 PM]
quote:Original post by nobodynews
Your problem was you weren''t using the result.


now you''ve gone and given them the answer when all they needed to do was just look at the code and read it properly. I''d pointed out the problem already but gave them room to work it out for themselves.
Thank you for the help guys! I really appreciate it
thank you "nobodysnews" I got it to work.!
nother crit, nuttin personal but..

please POST your question as well, don''t just say help with C++.. peeves me having to go in here to see what the subject is..

if it is a question I know little to nothing about I won''t be wasting my time and yours.

I fseek, therefore I fam.
I'll give you a beating like Rodney King who deserved it!=====================================Any and all ideas, theories, and text c2004,c2009 BrainDead Software. All Rights Reserved.
quote:Original post by drarem
please POST your question as well, don''t just say help with C++.. peeves me having to go in here to see what the subject is..


Yeah taking a few seconds to click on the subject and read the first line of the post is a real drag.
Can I post homework questions too?

This topic is closed to new replies.

Advertisement