need help

Aug 23, 2013 at 5:12pm
Hi, can someone explain to me the code written in here and what will be the result? sorry, cos my result abit seem to be wrong.
Last edited on Aug 27, 2013 at 4:10pm
Aug 23, 2013 at 5:19pm
It is a stupid code. Ask the question who wrote this code. The code has no any sense. It simply outputs 12 lines consisting of 13 occurenses of a letter entered by the user.
Last edited on Aug 23, 2013 at 5:22pm
Aug 24, 2013 at 10:37am
So if I enter "T", it will give

TTTTTTTTTTTTT
TTTTTTTTTTTTT

am I rite?
Aug 24, 2013 at 10:47am
Is that what you got when you ran the program?
Aug 25, 2013 at 3:01pm
yup
Aug 25, 2013 at 3:06pm
It is totally unimportant what you will enter because this statement

default: count = 12;

will be always executed.
Last edited on Aug 25, 2013 at 3:18pm
Aug 25, 2013 at 3:12pm
Somehow I don't think the OP meant to skip the break statements at the end of their switch case conditions.
Aug 25, 2013 at 3:19pm
@Computergeek01

Somehow I don't think the OP meant to skip the break statements at the end of their switch case conditions.



He meant nothing because it is not his code. He asked only to explain him this code what it does.
Last edited on Aug 25, 2013 at 3:51pm
Aug 25, 2013 at 3:24pm
I suppose it's possible, it just seems a little too bad for someone to have published it. Even as an example of "what not to do", it's missing a return statement so it won't even compile with strict warnings enabled.
Aug 25, 2013 at 3:53pm
@Computergeek01

it's missing a return statement so it won't even compile with strict warnings enabled.



There is no any need in the return statement.
Aug 25, 2013 at 3:55pm
That's fine, most of the time you don't even assign a meaning to the return statement. But that doesn't invalidate what I said about strict warnings preventing this from compiling.
Aug 25, 2013 at 4:06pm
@Computergeek01

That's fine, most of the time you don't even assign a meaning to the return statement. But that doesn't invalidate what I said about strict warnings preventing this from compiling.



I have not totally understood why you need that the valid program (that is without the return statement in main) will not be compiled.
Aug 25, 2013 at 4:12pm
I guess it doesn't actually matter vlad, if the code didn't come from OP then it is too messed up of an example to try to explain to someone who is still learning so this entire thread should just be allowed to die. If I don't respond to your next post here then don't take it personally, it's just that this is starting to feel like a game of "Who Can Get The Last Word In".
Last edited on Aug 25, 2013 at 4:13pm
Aug 26, 2013 at 12:33am
it should be like this...put a break there..then u will get wat u wan i guess..the result will be:
TTTT
TTTT
TTTT
if u want the result be three T per row..u jus delete the line cout alphabet before the inner loop..

#include <iostream>
using namespace std;
int main()
{
char alphabet = 'D';
int count;
cout << "Please enter an alphabet: ";
cin >> alphabet;
switch (alphabet)
{
case 'T' : count = 3;
break;
case 'S' : count = 6;
break;
case 'N': count = 9;
break;
default: count = 12;
}
for (int i = 0; i < count; i++) // outer loop
{
cout << alphabet ;
for (int j = 0 ; j < count; j++) // inner loop
cout << alphabet ;
cout << endl;
}
}//main
Aug 26, 2013 at 2:28am
thanks alot : )
Topic archived. No new replies allowed.