need help

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
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
So if I enter "T", it will give

TTTTTTTTTTTTT
TTTTTTTTTTTTT

am I rite?
Is that what you got when you ran the program?
yup
It is totally unimportant what you will enter because this statement

default: count = 12;

will be always executed.
Last edited on
Somehow I don't think the OP meant to skip the break statements at the end of their switch case conditions.
@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
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.
@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.
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.
@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.
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
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
thanks alot : )
Topic archived. No new replies allowed.