correction

A

aslamhenry

(e-mail address removed) View profile
More options Sep 18, 9:09 pm

Newsgroups: comp.lang.c++
From: (e-mail address removed)
Date: Tue, 18 Sep 2007 06:09:14 -0700
Local: Tues, Sep 18 2007 9:09 pm
Subject: hi can give me idea
Reply | Reply to author | Forward | Print | Individual message | Show
original | Remove | Report this message | Find messages by this
author
hem anyone can give me an idea on how to saparated digits using
looping

example


please key in any 5 digits number : 56789


and the ouput is
5678 9
567 89
56 789
5 6789



huhu how to saparate those digin huhuhu can help???anyone?


i prefer code in c..
 
J

Jim Langston

(e-mail address removed) View profile
More options Sep 18, 9:09 pm

Newsgroups: comp.lang.c++
From: (e-mail address removed)
Date: Tue, 18 Sep 2007 06:09:14 -0700
Local: Tues, Sep 18 2007 9:09 pm
Subject: hi can give me idea
Reply | Reply to author | Forward | Print | Individual message | Show
original | Remove | Report this message | Find messages by this
author
hem anyone can give me an idea on how to saparated digits using
looping

example

please key in any 5 digits number : 56789

and the ouput is
5678 9
567 89
56 789
5 6789

huhu how to saparate those digin huhuhu can help???anyone?

i prefer code in c..

This sounds like homework. What have you tried? You'l want to
treat/convert the digits as a string instead of a number.
 
A

aslamhenry

This sounds like homework. What have you tried? You'l want to
treat/convert the digits as a string instead of a number.- Hide quoted text -

- Show quoted text -

i've tried already by using for...and i use int...
 
A

aslamhenry

i've tried already by using for...and i use int...- Hide quoted text -

- Show quoted text -

erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu
 
V

Victor Bazarov

[..]
erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu

BTW, what's "uhuhu" or "huhuhu"?

V
 
J

Jim Langston

[..]
erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu

BTW, what's "uhuhu" or "huhuhu"?

V

huhuhu mean im crying..huhuhu almost 1 week im thinking on how to
saparate those number huhuhu

You were already given one way in another thread, with integer division.

Consider. What is
12345 / 10?
it is 1234
12345 / 100
123
what is the remainder of 12345 / 10?
45
to get the remainder, use 12345 % 10

That should be all you need to be able to write this. We will not do your
homework for you. You haven't show us ANY code that you've written to try
this.
 
A

aslamhenry

(e-mail address removed) wrote:
[..]
erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu
BTW, what's "uhuhu" or "huhuhu"?
V
huhuhu mean im crying..huhuhu almost 1 week im thinking on how to
saparate those number huhuhu

You were already given one way in another thread, with integer division.

Consider. What is
12345 / 10?
it is 1234
12345 / 100
123
what is the remainder of 12345 / 10?
45
to get the remainder, use 12345 % 10

That should be all you need to be able to write this. We will not do your
homework for you. You haven't show us ANY code that you've written to try
this.

ok i show my work..
but plss dont laugh at me coz im a newbie...
#include <stdio.h>

void main()
{
float num;


printf("please key in any 5 digit number:");
scanf("%f",&num);



for (int a=1 ; a<=5 ; a++)
{
printf("",a);
printf("\n%.0f", num);
}
huhu this is a beginner coding....
ok the problem is, i need to key in 56789 all togehther...so how to
make it saparated...
and where can i put the clue that u give
 
A

aslamhenry

(e-mail address removed) wrote:
[..]
erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu
BTW, what's "uhuhu" or "huhuhu"?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
huhuhu mean im crying..huhuhu almost 1 week im thinking on how to
saparate those number huhuhu
You were already given one way in another thread, with integer division.
Consider. What is
12345 / 10?
it is 1234
12345 / 100
123
what is the remainder of 12345 / 10?
45
to get the remainder, use 12345 % 10
That should be all you need to be able to write this. We will not do your
homework for you. You haven't show us ANY code that you've written to try
this.

ok i show my work..
but plss dont laugh at me coz im a newbie...
#include <stdio.h>

void main()
{
float num;

printf("please key in any 5 digit number:");
scanf("%f",&num);

for (int a=1 ; a<=5 ; a++)
{
printf("",a);
printf("\n%.0f", num);
}
huhu this is a beginner coding....
ok the problem is, i need to key in 56789 all togehther...so how to
make it saparated...
and where can i put the clue that u give- Hide quoted text -

- Show quoted text -

can u suggest how to simplify this coding

//assignment//

#include <stdio.h>



void main()
{
int m1,m2,m3 ;
float sum1=0,sum2=0,sum3=0,total;

printf ("\n 1.Appetizers:Rm 4.00 (10%Discount)\n 2.salads:Rm
3.00 (10%Discount)\n 3.Soups:Rm 3.50 (20%Discount)
\n 4.Seafood:Rm 5.00 (08%Discount)\n 5.Chicken/Beef:Rm 8.50
(15%Discount)\n 6.Noodles/Rice:Rm 3.50 (20%Discount)\n
7.Vegetables:Rm 3.00 (25%Discount)\n 8.Pasta:Rm 5.00
(15%Discount)\n 9.Beverages:Rm 2.00 (20%Discount)\n 10.Lunch
special:Rm 5.50 (25%Discount)\n 11.Healthy Food:Rm 6.00
(15%Discount)\n 12.Others:Rm 2.50 (5%Discount) ");
printf ("\n please enter 3 of the code above:\n");
scanf ("%d\n%d\n%d" ,&m1,&m2,&m3);

switch (m1)

{
case 1 : printf("Appetizers:Rm 4.00");
sum1=4.00-(4.00*10/100);
break ;

case 2 : printf("salads:Rm 3.00");
sum1=3.00-(3.00*10/100);
break ;
case 3 : printf("Soups:Rm 3.50");
sum1= 3.50-(3.50*20/100) ;
break ;
case 4 : printf("Seafood:Rm 5.00");
sum1= 5.00-(5.00*8/100);
break ;
case 5 : printf("Chicken/Beef:Rm 8.50");
sum1= 8.50-(8.50*15/100);
break ;
case 6 : printf("Noodles/Rice:Rm 3.50");
sum1= 3.50-(3.50*20/100);
break ;
case 7 : printf("Vegetables:Rm 3.00");
sum1= 3.00-(3.00*25/100) ;
break ;
case 8 : printf("Pasta:Rm 5.00");
sum1= 5.00-(5.00*15/100);
break ;
case 9 : printf("Beverages:Rm 2.00");
sum1= 2.00-(2.00*20/100);
break ;
case 10 : printf("Lunch special:Rm 5.50") ;
sum1=5.50-(3.50*25/100) ;
break ;
case 11 : printf("Healthy Food:Rm 6.00");
sum1=6.00-(6.00*15/100) ;
break ;
case 12 : printf("Others:Rm 2.50");
sum1= 2.50-(2.50*5/100);
default: ("asasd");

}


switch (m2)
{
case 1 : printf("\nAppetizers:Rm 4.00");
sum2= 4.00-(4.00*10/100);
break ;
case 2 : printf("\nsalads:Rm 3.00");
sum2= 3.00-(3.00*10/100) ;
break ;
case 3 : printf("\nSoups:Rm 3.50");
sum2= 3.50-(3.50*20/100) ;
break ;
case 4 : printf("\nSeafood:Rm 5.00");
sum2= 5.00-(5.00*8/100);
break ;
case 5 : printf("\nChicken/Beef:Rm 8.50");
sum2= 8.50-(8.50*15/100) ;
break ;
case 6 : printf("\nNoodles/Rice:Rm 3.50");
sum2= 3.50-(3.50*20/100) ;
break ;
case 7 : printf("\nVegetables:Rm 3.00");
sum2= 3.00-(3.00*25/100);
break ;
case 8 : printf("\nPasta:Rm 5.00");
sum2=5.00-(5.00*15/100);
break ;
case 9 : printf("\nBeverages:Rm 2.00");
sum2=2.00-(2.00*20/100) ;
break ;
case 10 : printf("\nLunch special:Rm 5.50") ;
sum2= 5.50-(5.50*25/100);
break ;
case 11 : printf("\nHealthy Food:Rm 6.00");
sum2= 6.00-(6.00*15/100);
break ;
case 12 : printf("\nOthers:Rm 2.50");
sum2= 2.50-(2.50*5/100) ;

default :("asasd");

}
switch (m3)
{

case 1 : printf("\nAppetizers:Rm 4.00");
sum3=4.00-(4.00*10/100) ;
break ;
case 2 : printf("\nsalads:Rm 3.00");
sum3=3.00-(3.00*10/ 100);
break ;
case 3 : printf("\nSoups:Rm 3.50");
sum3=3.50-(3.50*20/100);
break ;
case 4 : printf("\nSeafood:Rm 5.00");
sum3= 5.00-(5.00*8/100);
break ;
case 5 : printf("\nChicken/Beef:Rm 8.50");
sum3=8.50-(8.50*15/100);
break ;
case 6 : printf("\nNoodles/Rice:Rm 3.50");
sum3=3.50-(3.50*20/100);
break ;
case 7 : printf("\nVegetables:Rm 3.00");
sum3= 3.00-(3.00*25/100) ;
break ;
case 8 : printf("\nPasta:Rm 5.00");
sum3= 5.00-(5.00*15/100 );
break ;
case 9 : printf("\nBeverages:Rm 2.00");
sum3=2.00-(2.00*20/100);
break ;
case 10 : printf("\nLunch special:Rm 5.50") ;
sum3= 5.50-(5.50*25/100) ;
break ;
case 11 : printf("\nHealthy Food:Rm 6.00");
sum3=6.00-(6.00*15/100);
break ;
case 12 : printf("\nOthers:Rm 2.50");
sum3=2.50-(2.50*5/ 100);
default: ("asasd");
}

total = sum1+sum2+sum3 ;
printf("\n\nTotal price after discount RM%.2f",total);




}

____________________________________________________________________________________________________
i think we can use looping....but im suck in looping huhuhu realy2
sory....
 
A

aslamhenry

(e-mail address removed) wrote:
[..]
erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu
BTW, what's "uhuhu" or "huhuhu"?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
huhuhu mean im crying..huhuhu almost 1 week im thinking on how to
saparate those number huhuhu
You were already given one way in another thread, with integer division.
Consider. What is
12345 / 10?
it is 1234
12345 / 100
123
what is the remainder of 12345 / 10?
45
to get the remainder, use 12345 % 10
That should be all you need to be able to write this. We will not do your
homework for you. You haven't show us ANY code that you've written to try
this.
ok i show my work..
but plss dont laugh at me coz im a newbie...
#include <stdio.h>
void main()
{
float num;
printf("please key in any 5 digit number:");
scanf("%f",&num);
for (int a=1 ; a<=5 ; a++)
{
printf("",a);
printf("\n%.0f", num);
}
huhu this is a beginner coding....
ok the problem is, i need to key in 56789 all togehther...so how to
make it saparated...
and where can i put the clue that u give- Hide quoted text -
- Show quoted text -

can u suggest how to simplify this coding

//assignment//

#include <stdio.h>

void main()
{
int m1,m2,m3 ;
float sum1=0,sum2=0,sum3=0,total;

printf ("\n 1.Appetizers:Rm 4.00 (10%Discount)\n 2.salads:Rm
3.00 (10%Discount)\n 3.Soups:Rm 3.50 (20%Discount)
\n 4.Seafood:Rm 5.00 (08%Discount)\n 5.Chicken/Beef:Rm 8.50
(15%Discount)\n 6.Noodles/Rice:Rm 3.50 (20%Discount)\n
7.Vegetables:Rm 3.00 (25%Discount)\n 8.Pasta:Rm 5.00
(15%Discount)\n 9.Beverages:Rm 2.00 (20%Discount)\n 10.Lunch
special:Rm 5.50 (25%Discount)\n 11.Healthy Food:Rm 6.00
(15%Discount)\n 12.Others:Rm 2.50 (5%Discount) ");
printf ("\n please enter 3 of the code above:\n");
scanf ("%d\n%d\n%d" ,&m1,&m2,&m3);

switch (m1)

{
case 1 : printf("Appetizers:Rm 4.00");
sum1=4.00-(4.00*10/100);
break ;

case 2 : printf("salads:Rm 3.00");
sum1=3.00-(3.00*10/100);
break ;
case 3 : printf("Soups:Rm 3.50");
sum1= 3.50-(3.50*20/100) ;
break ;
case 4 : printf("Seafood:Rm 5.00");
sum1= 5.00-(5.00*8/100);
break ;
case 5 : printf("Chicken/Beef:Rm 8.50");
sum1= 8.50-(8.50*15/100);
break ;
case 6 : printf("Noodles/Rice:Rm 3.50");
sum1= 3.50-(3.50*20/100);
break ;
case 7 : printf("Vegetables:Rm 3.00");
sum1= 3.00-(3.00*25/100) ;
break ;
case 8 : printf("Pasta:Rm 5.00");
sum1= 5.00-(5.00*15/100);
break ;
case 9 : printf("Beverages:Rm 2.00");
sum1= 2.00-(2..00*20/100);
break ;
case 10 : printf("Lunch special:Rm 5.50") ;
sum1=5.50-(3.50*25/100) ;
break ;
case 11 : printf("Healthy Food:Rm 6.00");
sum1=6.00-(6.00*15/100) ;
break ;
case 12 : printf("Others:Rm 2.50");
sum1= 2.50-(2.50*5/100);
default: ("asasd");

}

switch (m2)
{
case 1 : printf("\nAppetizers:Rm 4.00");
sum2= 4.00-(4.00*10/100);
break ;
case 2 : printf("\nsalads:Rm 3.00");
sum2= 3.00-(3.00*10/100) ;
break ;
case 3 : printf("\nSoups:Rm 3.50");
sum2= 3.50-(3.50*20/100) ;
break ;
case 4 : printf("\nSeafood:Rm 5.00");
sum2= 5.00-(5..00*8/100);
break ;
case 5 : printf("\nChicken/Beef:Rm 8.50");
sum2= 8.50-(8..50*15/100) ;
break ;
case 6 : printf("\nNoodles/Rice:Rm 3.50");
sum2= 3.50-(3..50*20/100) ;
break ;
case 7 : printf("\nVegetables:Rm 3.00");
sum2= 3.00-(3.00*25/100);
break ;
case 8 : printf("\nPasta:Rm 5.00");
sum2=5.00-(5.00*15/100);
break ;
case 9 : printf("\nBeverages:Rm 2.00");
sum2=2.00-(2.00*20/100) ;
break ;
case 10 : printf("\nLunch special:Rm 5.50") ;
sum2= 5.50-(5..50*25/100);
break ;
case 11 : printf("\nHealthy Food:Rm 6.00");
sum2= 6.00-(6.00*15/100);
break ;
case 12 : printf("\nOthers:Rm 2.50");
sum2= 2.50-(2.50*5/100) ;

default :("asasd");

}
switch (m3)
{

case 1 : printf("\nAppetizers:Rm 4.00");
sum3=4.00-(4.00*10/100) ;
break ;
case 2 : printf("\nsalads:Rm 3.00");
sum3=3.00-(3.00*10/ 100);
break ;
case 3 : printf("\nSoups:Rm 3.50");
sum3=3.50-(3.50*20/100);
break ;
case 4 : printf("\nSeafood:Rm 5.00");
sum3= 5.00-(5.00*8/100);
break ;
case 5 : printf("\nChicken/Beef:Rm 8.50");
sum3=8.50-(8.50*15/100);
break ;
case 6 : printf("\nNoodles/Rice:Rm 3.50");
sum3=3.50-(3.50*20/100);
break ;
case 7 : printf("\nVegetables:Rm 3.00");
sum3= 3.00-(3.00*25/100) ;
break ;
case 8 : printf("\nPasta:Rm 5.00");
sum3= 5.00-(5..00*15/100 );
break ;
case 9 : printf("\nBeverages:Rm 2.00");
sum3=2.00-(2.00*20/100);
break ;
case 10 : printf("\nLunch special:Rm 5.50") ;
sum3= 5.50-(5.50*25/100) ;
break ;
case 11 : printf("\nHealthy Food:Rm 6.00");
sum3=6.00-(6.00*15/100);
break ;
case 12 : printf("\nOthers:Rm 2.50");
sum3=2.50-(2.50*5/ 100);
default: ("asasd");
}

total = sum1+sum2+sum3 ;
printf("\n\nTotal price after discount RM%.2f",total);

}

___________________________________________________________________________­_________________________
i think we can use looping....but im suck in looping huhuhu realy2
sory....- Hide quoted text -

- Show quoted text -

check out this code why it doesnt work huhuhu

#include <stdio.h>

int main(void)
{
float num;
int i, j, x ;

printf("please key in any 5 digit number:");
scanf("%f",&num);




for ( i=0 ; 5>i ; ++i){

for(j=0 ; i>j ; ++j){
printf(" ") ;
}

for( x = j+1 ; 5 >= x ; ++x){

printf("%.0f", num);
}
putchar('\n');
}

return 0;
}
 
A

Alexander Dong Back Kim

On Sep 18, 10:00 pm, (e-mail address removed) wrote:
(e-mail address removed) wrote:
[..]
erm...how about if im using float...ant printf as %.0f..huhuhu but
still i dont know how to saparate those digit as shown uhuhu
BTW, what's "uhuhu" or "huhuhu"?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
huhuhu mean im crying..huhuhu almost 1 week im thinking on how to
saparate those number huhuhu
You were already given one way in another thread, with integer division.
Consider. What is
12345 / 10?
it is 1234
12345 / 100
123
what is the remainder of 12345 / 10?
45
to get the remainder, use 12345 % 10
That should be all you need to be able to write this. We will not do your
homework for you. You haven't show us ANY code that you've written to try
this.
ok i show my work..
but plss dont laugh at me coz im a newbie...
#include <stdio.h>
void main()
{
float num;
printf("please key in any 5 digit number:");
scanf("%f",&num);
for (int a=1 ; a<=5 ; a++)
{
printf("",a);
printf("\n%.0f", num);
}
huhu this is a beginner coding....
ok the problem is, i need to key in 56789 all togehther...so how to
make it saparated...
and where can i put the clue that u give- Hide quoted text -
- Show quoted text -
can u suggest how to simplify this coding

#include <stdio.h>
void main()
{
int m1,m2,m3 ;
float sum1=0,sum2=0,sum3=0,total;
printf ("\n 1.Appetizers:Rm 4.00 (10%Discount)\n 2.salads:Rm
3.00 (10%Discount)\n 3.Soups:Rm 3.50 (20%Discount)
\n 4.Seafood:Rm 5.00 (08%Discount)\n 5.Chicken/Beef:Rm 8.50
(15%Discount)\n 6.Noodles/Rice:Rm 3.50 (20%Discount)\n
7.Vegetables:Rm 3.00 (25%Discount)\n 8.Pasta:Rm 5.00
(15%Discount)\n 9.Beverages:Rm 2.00 (20%Discount)\n 10.Lunch
special:Rm 5.50 (25%Discount)\n 11.Healthy Food:Rm 6.00
(15%Discount)\n 12.Others:Rm 2.50 (5%Discount) ");
printf ("\n please enter 3 of the code above:\n");
scanf ("%d\n%d\n%d" ,&m1,&m2,&m3);
switch (m1)
{
case 1 : printf("Appetizers:Rm 4.00");
sum1=4.00-(4.00*10/100);
break ;
case 2 : printf("salads:Rm 3.00");
sum1=3.00-(3.00*10/100);
break ;
case 3 : printf("Soups:Rm 3.50");
sum1= 3.50-(3.50*20/100) ;
break ;
case 4 : printf("Seafood:Rm 5.00");
sum1= 5.00-(5.00*8/100);
break ;
case 5 : printf("Chicken/Beef:Rm 8.50");
sum1= 8.50-(8.50*15/100);
break ;
case 6 : printf("Noodles/Rice:Rm 3.50");
sum1= 3.50-(3.50*20/100);
break ;
case 7 : printf("Vegetables:Rm 3.00");
sum1= 3.00-(3.00*25/100) ;
break ;
case 8 : printf("Pasta:Rm 5.00");
sum1= 5.00-(5.00*15/100);
break ;
case 9 : printf("Beverages:Rm 2.00");
sum1= 2.00-(2.00*20/100);
break ;
case 10 : printf("Lunch special:Rm 5.50") ;
sum1=5.50-(3..50*25/100) ;
break ;
case 11 : printf("Healthy Food:Rm 6.00");
sum1=6.00-(6..00*15/100) ;
break ;
case 12 : printf("Others:Rm 2.50");
sum1= 2.50-(2.50*5/100);
default: ("asasd");

switch (m2)
{
case 1 : printf("\nAppetizers:Rm 4.00");
sum2= 4.00-(4.00*10/100);
break ;
case 2 : printf("\nsalads:Rm 3.00");
sum2= 3.00-(3..00*10/100) ;
break ;
case 3 : printf("\nSoups:Rm 3.50");
sum2= 3.50-(3.50*20/100) ;
break ;
case 4 : printf("\nSeafood:Rm 5.00");
sum2= 5.00-(5.00*8/100);
break ;
case 5 : printf("\nChicken/Beef:Rm 8.50");
sum2= 8.50-(8.50*15/100) ;
break ;
case 6 : printf("\nNoodles/Rice:Rm 3.50");
sum2= 3.50-(3.50*20/100) ;
break ;
case 7 : printf("\nVegetables:Rm 3.00");
sum2= 3.00-(3.00*25/100);
break ;
case 8 : printf("\nPasta:Rm 5.00");
sum2=5.00-(5.00*15/100);
break ;
case 9 : printf("\nBeverages:Rm 2.00");
sum2=2.00-(2..00*20/100) ;
break ;
case 10 : printf("\nLunch special:Rm 5.50") ;
sum2= 5.50-(5.50*25/100);
break ;
case 11 : printf("\nHealthy Food:Rm 6.00");
sum2= 6.00-(6.00*15/100);
break ;
case 12 : printf("\nOthers:Rm 2.50");
sum2= 2.50-(2.50*5/100) ;
default :("asasd");
}
switch (m3)
{
case 1 : printf("\nAppetizers:Rm 4.00");
sum3=4.00-(4.00*10/100) ;
break ;
case 2 : printf("\nsalads:Rm 3.00");
sum3=3.00-(3.00*10/ 100);
break ;
case 3 : printf("\nSoups:Rm 3.50");
sum3=3.50-(3.50*20/100);
break ;
case 4 : printf("\nSeafood:Rm 5.00");
sum3= 5.00-(5..00*8/100);
break ;
case 5 : printf("\nChicken/Beef:Rm 8.50");
sum3=8.50-(8..50*15/100);
break ;
case 6 : printf("\nNoodles/Rice:Rm 3.50");
sum3=3.50-(3.50*20/100);
break ;
case 7 : printf("\nVegetables:Rm 3.00");
sum3= 3.00-(3..00*25/100) ;
break ;
case 8 : printf("\nPasta:Rm 5.00");
sum3= 5.00-(5.00*15/100 );
break ;
case 9 : printf("\nBeverages:Rm 2.00");
sum3=2.00-(2.00*20/100);
break ;
case 10 : printf("\nLunch special:Rm 5.50") ;
sum3= 5.50-(5.50*25/100) ;
break ;
case 11 : printf("\nHealthy Food:Rm 6.00");
sum3=6.00-(6.00*15/100);
break ;
case 12 : printf("\nOthers:Rm 2.50");
sum3=2.50-(2.50*5/ 100);
default: ("asasd");
}
total = sum1+sum2+sum3 ;
printf("\n\nTotal price after discount RM%.2f",total);

___________________________________________________________________________­_________________________
i think we can use looping....but im suck in looping huhuhu realy2
sory....- Hide quoted text -
- Show quoted text -

check out this code why it doesnt work huhuhu

#include <stdio.h>

int main(void)
{
float num;
int i, j, x ;

printf("please key in any 5 digit number:");
scanf("%f",&num);

for ( i=0 ; 5>i ; ++i){

for(j=0 ; i>j ; ++j){
printf(" ") ;
}

for( x = j+1 ; 5 >= x ; ++x){

printf("%.0f", num);
}
putchar('\n');
}

return 0;
}

Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Cheers,
 
V

Victor Bazarov

Dong said:
[..]
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Are you saying you saw it before and thought it was illegal or
what? How could it not be acceptable? It's not what one would
call "common", of course...

V
 
R

Rolf Magnus

Victor said:
Dong said:
[..]
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Why shouldn't it?
Are you saying you saw it before and thought it was illegal or
what? How could it not be acceptable? It's not what one would
call "common", of course...

I would call it quite common.
 
V

Victor Bazarov

Rolf said:
Victor said:
Dong said:
[..]
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Why shouldn't it?
Are you saying you saw it before and thought it was illegal or
what? How could it not be acceptable? It's not what one would
call "common", of course...

I would call it quite common.

Really? Quite common where? Among whom? Obfuscators in an asylum?
I can understand the use of NULL or 0 on the left side of ==, maybe.
But non-symmetrical operator (>=)?... I am yet to see such code
in a production codebase.

V
 
J

Joe Greer

Rolf said:
Victor said:
Dong Back Kim wrote:
[..]
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Why shouldn't it?
Are you saying you saw it before and thought it was illegal or
what? How could it not be acceptable? It's not what one would
call "common", of course...

I would call it quite common.

Really? Quite common where? Among whom? Obfuscators in an asylum?
I can understand the use of NULL or 0 on the left side of ==, maybe.
But non-symmetrical operator (>=)?... I am yet to see such code
in a production codebase.

V

There's a whole group of folk who try to prevent:

if (a == 5) ...

from accidentally turning into:

if (a = 5)

by requiring that you write the bass ackwards:

if (5 == a)

of course, these same folk then think well... if they can drop the '='
then they can also drop the '>' so lets do those backwards too. Sadly,
they usually don't realize that that same reasoning gets rid of all the
assignment operators as well. (+=, -= *= /= etc) because after all, you
might drop a character.

The whole thing is pretty silly since almost all C++ compilers can be
made to provide a warning for an assignment inside an 'if'. (with VC++
it comes with warning level 4, but you can explicitly turn it on as
well).

Personally, I don't find the embedded assignment any harder to debug
than any other problem you encounter, so I don't see the point.

joe
 
V

Victor Bazarov

Joe said:
Rolf said:
Victor Bazarov wrote:

Dong Back Kim wrote:
[..]
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Why shouldn't it?

Are you saying you saw it before and thought it was illegal or
what? How could it not be acceptable? It's not what one would
call "common", of course...

I would call it quite common.

Really? Quite common where? Among whom? Obfuscators in an asylum?
I can understand the use of NULL or 0 on the left side of ==, maybe.
But non-symmetrical operator (>=)?... I am yet to see such code
in a production codebase.

V

There's a whole group of folk who try to prevent:

if (a == 5) ...

from accidentally turning into:

if (a = 5)

by requiring that you write the bass ackwards:

if (5 == a)

of course, these same folk then think well... if they can drop the '='

It's not the matter of "dropping" the '='. It's actually because of
using '=' for equality, which they learned from Basic, Pascal, and so
on. Pascal has ':=' for assignment. Basic... well, let's not discuss
Basic here, shall we?
then they can also drop the '>' so lets do those backwards too.

This is unfortunately a speculation of somebody who does not use that
form of comparison (am I right?) I hoped Rolf would give some proof
of his "quite common" assertion.

V
 
R

Rolf Magnus

Victor said:
Rolf said:
Victor said:
Dong Back Kim wrote:
[..]
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Why shouldn't it?
Are you saying you saw it before and thought it was illegal or
what? How could it not be acceptable? It's not what one would
call "common", of course...

I would call it quite common.

Really? Quite common where? Among whom?

C and C++ programmers.
Obfuscators in an asylum?

I'd say rather the opposite.
I can understand the use of NULL or 0 on the left side of ==, maybe.

Then it shouldn't be a surprise that some programmers do that with the other
relational operators too, for the sake of consistency.
 
R

Rolf Magnus

Victor said:
It's not the matter of "dropping" the '='.

I think it is.

I'd say the reason here is rather consistency. If you put the literal on the
left in one place, it's more consistent to do that everywhere.
This is unfortunately a speculation of somebody who does not use that
form of comparison (am I right?) I hoped Rolf would give some proof
of his "quite common" assertion.

Not sure what proof you mean. I can't show you any production code that does
it, but I have seen it. Maybe it's not "quite common", but neither is it as
exotic as you made it sound.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,293
Latest member
BonnieHamb

Latest Threads

Top