Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


First Difficult Coding C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NeverForgotten
Grandmaster Cheater Supreme
Reputation: 2

Joined: 20 Oct 2007
Posts: 1616
Location: Wii

PostPosted: Mon Sep 21, 2009 7:16 pm    Post subject: First Difficult Coding C++ Reply with quote

Our teacher has given us this assignment

Write a program that inputs number from the user and prints out all
the squares from 1 to that number

We have recently finished a guessing game that ask the user for the range input and you guess a number between that range

Now at this assignment
I have a basic Cout command
and i just get stuck from there

_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Sep 21, 2009 7:36 pm    Post subject: Reply with quote

something like this ?

Code:
#include <iostream>
  using namespace std;

int main()
{
  int x;

  cout << "enter choice: ";
  cin >> x;

  for( int i = 1; i*i <= x; i++ )
    cout << i*i << "\n";

  cin >> x;

  return 0;
}
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Sep 21, 2009 7:49 pm    Post subject: Reply with quote

I wasn't sure if you meant x number squared or square root

Code:
#include <iostream>

int main()
{
   int butt;
   std::cin >> butt;

   for(int i = 0; i <= butt; i++)
      std::cout << (i * i) << std::endl;

   return 0;
}


Code:
#include <iostream>
#include <cmath>

int main()
{
   int dong;
   std::cin >> dong;

   for(int i = 0; i < (dong + 1); i++)
      std::cout << sqrt((float)i) << std::endl;

   return 0;
}


Code:
#include <iostream>
#include <cstdlib>

int main()
{
   int low, high, r, guess = 0;
   std::cin >> low >> high;

   r = (rand()%((high - low) + 1) + low);
   
   while(guess != r)
      std::cin >> guess;

   return 0;
}
Back to top
View user's profile Send private message
NeverForgotten
Grandmaster Cheater Supreme
Reputation: 2

Joined: 20 Oct 2007
Posts: 1616
Location: Wii

PostPosted: Mon Sep 21, 2009 8:06 pm    Post subject: Reply with quote

Thanks Slugsmack I'll try that code
Do you know any guides or tutorials that would help me with these kinds of codes?

Well I mean if i put 16, it would display these numbers and possibly square 16 as well
1,2 9,16

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Sep 21, 2009 8:17 pm    Post subject: Reply with quote

I gave you a link in the last thread you posted...

cplusplus.com

I'm not entirely sure what you want? No idea where you got 2 from for 16

Code:
for(int i = 0; (i * i) <= butt; i++)

16 will output
0 1 4 9 16, which is 4 squared.

Code:
for(int i = 0; i <= butt; i++)

16 will output all the way up to 256, which is 16 squared
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Sep 21, 2009 8:18 pm    Post subject: Reply with quote

slovach wrote:
I gave you a link in the last thread you posted...

cplusplus.com

I'm not entirely sure what you want? No idea where you got 2 from for 16

Code:
for(int i = 0; (i * i) <= butt; i++)

16 will output
0 1 4 9 16, which is 4 squared.

Code:
for(int i = 0; i <= butt; i++)

16 will output all the way up to 256, which is 16 squared

He wanted from 1 to 'that number'
Back to top
View user's profile Send private message
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Mon Sep 21, 2009 8:40 pm    Post subject: Re: First Difficult Coding C++ Reply with quote

Slugsnack,

NeverForgotten wrote:
the squares from 1 to that number


A square is the product of a number multiplied by itself.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Sep 21, 2009 8:45 pm    Post subject: Re: First Difficult Coding C++ Reply with quote

talkerzero wrote:
Slugsnack,

NeverForgotten wrote:
the squares from 1 to that number


A square is the product of a number multiplied by itself.

yes, i meant the squares. it's clear i understood the question from the first code snippet i provided. i was letting slovach know 0 should not be one of the elements shown
Back to top
View user's profile Send private message
NeverForgotten
Grandmaster Cheater Supreme
Reputation: 2

Joined: 20 Oct 2007
Posts: 1616
Location: Wii

PostPosted: Mon Sep 21, 2009 9:35 pm    Post subject: Reply with quote

I can't seem to find anything on cplusplus.com that deals with these kinds of aspects

Also he just wants the user to input a number and I output numbers that square from that number from 1

_________________
Back to top
View user's profile Send private message
igoticecream
Grandmaster Cheater Supreme
Reputation: 0

Joined: 23 Apr 2006
Posts: 1807
Location: 0x00400000

PostPosted: Tue Sep 22, 2009 6:54 pm    Post subject: Reply with quote

Here is another solution, i love the code that use recursion

Code:

void Calc(__in int TopNumber, __in int LowNumber)
{
   if((LowNumber) < (TopNumber)) 
      Calc(TopNumber,LowNumber+1);
   printf("Square of %d is: %d\n",LowNumber,(LowNumber*LowNumber));
}

int _tmain(int argc, _TCHAR* argv[])
{
   int TopNumber;
   printf_s("Input a number: ");
   scanf_s("%d",&TopNumber);
   Calc(TopNumber,1);
   return 0;
}
Back to top
View user's profile Send private message
NeverForgotten
Grandmaster Cheater Supreme
Reputation: 2

Joined: 20 Oct 2007
Posts: 1616
Location: Wii

PostPosted: Tue Sep 22, 2009 8:35 pm    Post subject: Reply with quote

igoticecream wrote:
Here is another solution, i love the code that use recursion

Code:

void Calc(__in int TopNumber, __in int LowNumber)
{
   if((LowNumber) < (TopNumber)) 
      Calc(TopNumber,LowNumber+1);
   printf("Square of %d is: %d\n",LowNumber,(LowNumber*LowNumber));
}

int _tmain(int argc, _TCHAR* argv[])
{
   int TopNumber;
   printf_s("Input a number: ");
   scanf_s("%d",&TopNumber);
   Calc(TopNumber,1);
   return 0;
}


Thanks but it would be great if you could use a more simpler code
as we dont use printf, calc, etc
its more cout, and + etc

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites