473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

a c++ program printing squares and cube but using if statement only

hello everyone

may someone please help me with this c++ program.

i'm developing a program that will print numbers from 0 to 10 which must appear like a table but i;m only allowed to use if statement only and that program must take any number apart from 0-10.
the program should look like this.

integer square cube
0 0 0
1 1 1
2 4 8

i will be so much pleased if someone out there may help me.
May 10 '07 #1
10 13314
JosAH
11,448 Expert 8TB
So 'for', 'while' and 'do' loops are not allowed. Recursion mayhap or a filthy 'goto'
statement by any chance? Is that allowed by your assignment text?

kind regards,

Jos
May 10 '07 #2
So 'for', 'while' and 'do' loops are not allowed. Recursion mayhap or a filthy 'goto'
statement by any chance? Is that allowed by your assignment text?

kind regards,

Jos
no sir what is allowed is only if statement only. and at the same same time it has to appear in a table form.and it is an assignment
May 10 '07 #3
no sir what is allowed is only if statement only. and at the same same time it has to appear in a table form.and it is an assignment
what i did is i used this information to do it.but the problem is it doesn;t appear like it should be.i did like this.i used 11 letters because i'm printing 0-10

#include<iostream>

using namespace std;
using std::endl;
using std::cin;
using::std cout;

int main( )
{
int a;int b;int c;int d;int e;int f;int g;int h;int i;int j;int k;
int square;
int cube;

cout<<"integer any integer"<<endl;
cout<<"integer\t<<square\t<<cube<<endl;
cin>>a;
square=a*a;
cube=a*a*a;

cout<<a<<"\t"<<square<<"\t"<<cube<<endl;

so i repeated this statement 11 times and it appeared like this.

integer square cube
0 0 0
1
1 1 1
2
2 2 2

so i want to know how to remove this between numbers,
May 10 '07 #4
hello u all.may someone help me with a c++ program that is printing integers from 0-10 with their squares and cubes in a table form but using if only statement.

what i did is this:and my problem is i want to remove the numbers in between

#include<iostream>

using namespace std:
using std::cout;cin;endl;

int main( )
{ int a;b;c;d;e;f;g;h;i;j;k
int square;
int cube;

cout<<"enteger any integer"<<endl;
cin<<a;
square=a*a;
cube=a*a*a;

cout<<a<<"\t"<<square<<"\t"<<cube<<endl;

so i repeated the statement 11 times. my problem is it appears like this

integer square cube
0 0 0
1
1 1 1
2
2 2 2

so how can i remove the numbers in between?
please help
May 10 '07 #5
r035198x
13,262 8TB
hello u all.may someone help me with a c++ program that is printing integers from 0-10 with their squares and cubes in a table form but using if only statement.

what i did is this:and my problem is i want to remove the numbers in between

#include<iostream>

using namespace std:
using std::cout;cin;endl;

int main( )
{ int a;b;c;d;e;f;g;h;i;j;k
int square;
int cube;

cout<<"enteger any integer"<<endl;
cin<<a;
square=a*a;
cube=a*a*a;

cout<<a<<"\t"<<square<<"\t"<<cube<<endl;

so i repeated the statement 11 times. my problem is it appears like this

integer square cube
0 0 0
1
1 1 1
2
2 2 2

so how can i remove the numbers in between?
please help
Do not double post. Keep one problem in one thread. It's easier for everyone that way.

Threads merged.
May 10 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
Your code sample does not compile due to syntax errors. How can you get output from code that won't compile?
May 10 '07 #7
Your code sample does not compile due to syntax errors. How can you get output from code that won't compile?
i'm giving u again sir;it is compiling sir

#include<iostream>

using namespace std:
using std::cout;
using std::cin;
using std::endl;

int main()
{
int a;int b;int c;int d;int e;int f;int g;int h;int i;int j;int k;
int square;
int cube;

cout<<"enteger any number"<<endl;
cin>>a;
square=a*a;
cube=a*a*a;

cout<<a<<"\t"<<square<<"\t"<<cube<<endl;

cin>>b;
square=b*b;
cube=b*b*b;

cout<<b<<"\t"<<square<<"\t"cube<<endl;



return 0;
}
May 10 '07 #8
weaknessforcats
9,208 Expert Mod 8TB
It still won't compile. There are errors in these two lines:
Expand|Select|Wrap|Line Numbers
  1. using namespace std:
  2. cout<<b<<"\t"<<square<<"\t"cube<<endl;
  3.  
However, I fixed them and when I enter 2 and a 3 my output is:

2
2 4 8
3
3 9 27

which is correct for the code.

Now if you are trying to make look like this:

2 4 8
3 9 27

then you can't have those cin>> lines throughout the code. You are seeing the echo from your data entry. You will need to have one cin>> at the beginning, enter all the numbers and then display all the results.
May 11 '07 #9
JosAH
11,448 Expert 8TB
I find this assignment extremely silly the way it is described now. The tabular
output simply screams for some form of loop. Just 'if statements' don't mean much.
I'm afraid the OP misunderstood some requirements.

kind regards,

Jos
May 11 '07 #10
It still won't compile. There are errors in these two lines:
Expand|Select|Wrap|Line Numbers
  1. using namespace std:
  2. cout<<b<<"\t"<<square<<"\t"cube<<endl;
  3.  
However, I fixed them and when I enter 2 and a 3 my output is:

2
2 4 8
3
3 9 27

which is correct for the code.

Now if you are trying to make look like this:

2 4 8
3 9 27

then you can't have those cin>> lines throughout the code. You are seeing the echo from your data entry. You will need to have one cin>> at the beginning, enter all the numbers and then display all the results.
thanks for your help but still i want to know if i want to have that one cin statement only how must i do it?
May 11 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mrwoopey | last post by:
Hi, My OLAP data cube is giving me the following error when I am manipulating OLAP data cube views: "the data being processed is over the allowed limit" I know that this message is caused by...
0
by: mrwoopey | last post by:
Hi, I am using the OLAP data cube in a web browser (using the code from the SQL 2000 toolkit). The OLAP services is on database server and the web interface is on the web server. If we do simple...
3
by: Pradeep | last post by:
I have created a crystal report connecting an OLAP cube .But once i try to view a report it took around 15 minutes and finaly gave an error like "cannot retrieve data from cube".I want to know why...
5
by: Matt | last post by:
I will be grateful if someone explians this part colfree = FALSE; upfree = FALSE; downfree = FALSE; of the code below. I don't understand how this marks the downward and upward diagonals....
40
by: findmadhav | last post by:
I need a program in C (something like a TSR) which will automatically press the function key F6, say about every 5 seconds. Can anyone provide me with an exe of such a program? Thanks in advance.
11
by: Grzesiek | last post by:
Hi I have Main.cpp and Hello.cpp files in my Dev C++ project. Main.cpp #include "Hello.cpp" int main(){ return 0;
4
by: sathyancse | last post by:
Hi, i found the new method of find cube root of the given value.i want to implement in the c++ program.ex: if you give the answer the certain value i find the cube value.(i.e)if you give the...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.