473,395 Members | 1,678 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,395 software developers and data experts.

correction



aslamhe...@yahoo.com View profile
More options Sep 18, 9:09 pm

Newsgroups: comp.lang.c++
From: aslamhe...@yahoo.com
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..

Sep 18 '07 #1
27 1507
<as********@yahoo.comwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
>

aslamhe...@yahoo.com View profile
More options Sep 18, 9:09 pm

Newsgroups: comp.lang.c++
From: aslamhe...@yahoo.com
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.
Sep 18 '07 #2
as********@yahoo.com wrote:
[...homework...]

i prefer code in c..
FAQ 5.2, and the rest of the section 5, like where to post.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #3
On Sep 18, 9:14 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aslamhe...@yahoo.comwrote in message

news:11*********************@k79g2000hse.googlegro ups.com...


aslamhe...@yahoo.com View profile
More options Sep 18, 9:09 pm
Newsgroups: comp.lang.c++
From: aslamhe...@yahoo.com
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.- Hide quoted text -

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

Sep 18 '07 #4
as********@yahoo.com wrote:
[..]

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

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #5
On Sep 18, 9:21 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 9:14 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:


<aslamhe...@yahoo.comwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
aslamhe...@yahoo.com View profile
More options Sep 18, 9:09 pm
Newsgroups: comp.lang.c++
From: aslamhe...@yahoo.com
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.- Hide quoted text -
- Show quoted text -

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

Sep 18 '07 #6
as********@yahoo.com 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
Sep 18 '07 #7
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
aslamhe...@yahoo.com 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

Sep 18 '07 #8
<as********@yahoo.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>aslamhe...@yahoo.com 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.
Sep 18 '07 #9
On Sep 18, 9:54 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aslamhe...@yahoo.comwrote in message

news:11**********************@y42g2000hsy.googlegr oups.com...
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
aslamhe...@yahoo.com 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

Sep 18 '07 #10
On Sep 18, 10:00 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 9:54 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:


<aslamhe...@yahoo.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>aslamhe...@yahoo.com 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....

Sep 18 '07 #11
On Sep 18, 10:05 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 10:00 pm, aslamhe...@yahoo.com wrote:


On Sep 18, 9:54 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aslamhe...@yahoo.comwrote in message
>news:11**********************@y42g2000hsy.googleg roups.com...
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
aslamhe...@yahoo.com 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 doyour
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;
}

Sep 18 '07 #12
On Sep 19, 1:04 am, aslamhe...@yahoo.com wrote:
On Sep 18, 10:05 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 10:00 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 9:54 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aslamhe...@yahoo.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>aslamhe...@yahoo.com wrote:
[..]
erm...how about if im using float...ant printf as %.0f..huhuhubut
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 writtento 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;
}
Very interesting code style "5>=x". I didn't even know it's an
acceptable expression.

Cheers,

Sep 18 '07 #13
Dong Back Kim wrote:
[..]
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #14
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.
Sep 18 '07 #15
Rolf Magnus wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #16
"Victor Bazarov" <v.********@comAcast.netwrote in news:fcp1sc$bcs$1
@news.datemas.de:
Rolf Magnus wrote:
>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 '='
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
Sep 18 '07 #17
Joe Greer wrote:
"Victor Bazarov" <v.********@comAcast.netwrote in news:fcp1sc$bcs$1
@news.datemas.de:
>Rolf Magnus wrote:
>>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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #18
Victor Bazarov wrote:
Rolf Magnus wrote:
>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?
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.

Sep 18 '07 #19
Victor Bazarov wrote:
>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 '='.
I think it is.
>then they can also drop the '>' so lets do those backwards too.
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.

Sep 18 '07 #20
Rolf Magnus wrote:
Victor Bazarov wrote:
>>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 '='.

I think it is.
>>then they can also drop the '>' so lets do those backwards too.

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 don't know. You made the claim, you're supposed to supply the proof.
I will be the judge of whether it looks like a proof to me or not.
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.
I have *never* seen it in all millions of lines of production code
that passed in front of my eyes over the past twenty years. *Never*.
Not that it makes it necessarily exotic; for all I know, I've not even
seen one millionth of the code out there, and it is possible (although
not necessarily probable) that the code I didn't see is riddled with
expressions like that. But I doubt it.

Out of all posters here nobody came out saying "I do it all the time",
not even you. So, how could you call it "common"? OK, you say it's
not "quite common", but how common is it, then? "Not common", maybe?
"Quite uncommon"? "Unusual" (antonym for "usual")?...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 18 '07 #21
<as********@yahoo.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
On Sep 18, 10:05 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 10:00 pm, aslamhe...@yahoo.com wrote:
On Sep 18, 9:54 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aslamhe...@yahoo.comwrote in message
>news:11**********************@y42g2000hsy.googleg roups.com...
On Sep 18, 9:30 pm, "Victor Bazarov" <v.Abaza...@comAcast.net>
wrote:
aslamhe...@yahoo.com 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"?
[Snip previous discussion and unrelated code]
check out this code why it doesnt work huhuhu

#include <stdio.h>

int main(void)
{
float num;
int i, j, x ;
In C++ it is customary to declare variables as close to their first use as
possible. So get rid of the
int i,j,x;
since we're not using them yet.
printf("please key in any 5 digit number:");
scanf("%f",&num);
Since you are asking in a C++ newsgroup and not C, you should do it the C++
way.

#include <iostream>
at top.

std::cin >num;
for ( i=0 ; 5>i ; ++i){
for ( int i = 0; i <= 5; ++i )
is more common.
for(j=0 ; i>j ; ++j){
printf(" ") ;
}
That looks okay.
for( x = j+1 ; 5 >= x ; ++x){

printf("%.0f", num);
}
putchar('\n');
}
But, you have a 5 digit number. First you want to print all 5 digits.
Which would be the number / 1
Then print 4 digits, number / 10
then print 3 digits, number / 100
see a pattern?

Consider:

std::cout << num / ( i * 10 );
Then you would want to print a space.
std::cout << " ";
Then you would want to print the remainder.
std::cout << num % ( i * 10 );
return 0;
}
Since you are asking in a C++ newsgroup, don't use printf, use std::cout.
Don't use scanf, use std::cin.
Sep 19 '07 #22
On Sep 19, 1:11 am, aslamhe...@yahoo.com wrote:
huhu how to saparate those digin huhuhu can help???anyone?
What does 'huhu' and 'huhuhu' mean? I know an
Asian who uses those expressions (or even 'huhuhuhu'),
but when I ask her what they mean, she doesn't seem
to understand the question.
Sep 19 '07 #23
On Sep 19, 12:34 pm, Old Wolf <oldw...@inspire.net.nzwrote:
On Sep 19, 1:11 am, aslamhe...@yahoo.com wrote:
huhu how to saparate those digin huhuhu can help???anyone?

What does 'huhu' and 'huhuhu' mean? I know an
Asian who uses those expressions (or even 'huhuhuhu'),
but when I ask her what they mean, she doesn't seem
to understand the question
huhu is like a crying sound.....

Sep 19 '07 #24
Victor Bazarov wrote:
Rolf Magnus wrote:
>Victor Bazarov wrote:
>>>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)
I do this all the time for that reason.
>>>>
of course, these same folk then think well... if they can drop the
'='
It's not the matter of "dropping" the '='.
I think it is.
>>>then they can also drop the '>' so lets do those backwards too.
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 don't know. You made the claim, you're supposed to supply the proof.
I will be the judge of whether it looks like a proof to me or not.
>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.

Out of all posters here nobody came out saying "I do it all the time",
not even you. So, how could you call it "common"? OK, you say it's
not "quite common", but how common is it, then? "Not common", maybe?
"Quite uncommon"? "Unusual" (antonym for "usual")?...
I do it sometimes. Not sure why. Probably when I get limits like for
example this:
0 <= a <= 0.6
then I would do:
if ( ( 0.0 <= a ) && ( a <= 0.6 ) )
....

Sep 19 '07 #25
On Tue, 18 Sep 2007 22:23:31 +0200, Victor Bazarov
<v.********@comacast.netwrote:
Out of all posters here nobody came out saying "I do it all the time",
not even you. So, how could you call it "common"? OK, you say it's
not "quite common", but how common is it, then? "Not common", maybe?
"Quite uncommon"? "Unusual" (antonym for "usual")?...

V
C++ coding guidelines where I am working state that "In logical statements
with constants, the constant should be on the left side of the conditional
expression".
And the question "Do I have a constant there" before typing the logical
statement has never been harmful to me.
Sep 19 '07 #26
"Victor Bazarov" <v.********@comAcast.netwrote in news:fcp4ur$mou$1
@news.datemas.de:
>
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?
Yes, it is. The convention is to prevent an accidental assignment.
>
>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.
No, it is officially the rule here for the very reason I mentioned.
Fortunately, it isn't enforced, but that is the justification for the rule.

joe
Sep 19 '07 #27
Émeric Dupont wrote:
:: On Tue, 18 Sep 2007 22:23:31 +0200, Victor Bazarov
:: <v.********@comacast.netwrote:
::
::: Out of all posters here nobody came out saying "I do it all the
::: time", not even you. So, how could you call it "common"? OK,
::: you say it's not "quite common", but how common is it, then?
::: "Not common", maybe? "Quite uncommon"? "Unusual" (antonym for
::: "usual")?...
:::
::: V
:: C++ coding guidelines where I am working state that "In logical
:: statements with constants, the constant should be on the left side
:: of the conditional expression".
:: And the question "Do I have a constant there" before typing the
:: logical statement has never been harmful to me.

Another reasonable guideline would be not using constants (literals)
in logical statements. They should first be given a readable name in a
const declaration.

Bo Persson
Sep 19 '07 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Yannick Turgeon | last post by:
Oups! I did a typing error in my last post. Fixed. ----------- Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem...
3
by: flab ba | last post by:
Hello: I am new to web app programming, but need to create a web app. I would like to do it in Python After extensive googling, reading news groups, blogs, and outdated / incomplete "web app...
9
by: Xah Lee | last post by:
here's a interesting real-world algoritm to have fun with. attached below is the Perl documentation that i wrote for a function called "reduce", which is really the heart of a larger software. ...
22
by: Phil Powell | last post by:
<script> <!-- function isValidAlert() { for (var i = 0; i < document.alertForm.length; i++) { with (document.alertForm.elements) { if (.name == "text" || .name == "password" || .name ==...
1
by: Barry | last post by:
Retoring Caret Position after text field correction -------------------------------------------------------------------------------- Hi, my code has the following form - function...
5
by: DU | last post by:
Hi! I really need to understand what is so-called browser error correction mechanisms. Can you explain this? I read somewhere (and I no longer can find where I read that) that browsers try to...
6
by: Peter Reinde | last post by:
I'm looking for information on how to do red-eye correction. But can't find any information on it? Do any of you know where i can find information or examples? - Peter
36
by: Jules | last post by:
All, how do I describe a string consisting of any number of characters, with an optional (but unique when occuring) end-of-line expression '/'? With groups if possible, as in...
4
by: fAnSKyer | last post by:
very same as Microsoft Word word correction, or like Gmail's word correction, if you choose a word, it gives you several candidate and if none is okay, user can type one. I want develop it in...
2
by: Ehud Banai | last post by:
Hi All, Is there any script or dll that allows me to do auto correction to digital pictures from PHP? Thanks in advance, Ehud
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.