Turbo C/C++ and other junk compilers help, discussions and queries here

The Incredible

Ambassador of Buzz
thanks abhra_life

n thanks u all fro answering.


esp. mach


A BILLION DOLLAR THANKZ

That's what i exactly wanted.
i copied whole tutorial.

u were correct only half n hour n problem solved.

but on 20th my maths exams.
22 social sc
24 science
26 english
27hindi
29 comp theory
30 comp prac.

now i'll read da tutz ASAP but in case of practice i'll do it on 27 after hindi paper.

Hey anubhav_har

don't b angry with me.

u don't know me.

i buy digit just coz i luv computer tech

also this forum n u ppl may not b available thru out my life.

may b i don't get time for my comp craze.

may b life

who knows?

i can't explain how much big fan of computing.

actually i'm giving time 2 this forum coz i'm knowing i'll b helped here
instead of searching da net. try 2 understand me.

i'm devoting time 2 forum just bcoz my comp exams.
either u believe or not i'm gonna take comp sc in 1sst yr. even if i've to leave cbse board.

plz answer me.

Thanks every1 for that kinda help.

Thanks mach. thanks a lot. i'm not getting words fro how 2 thanks u.


Anindya
 

The Incredible

Ambassador of Buzz
Here's da second last part of my QB

Use of else-if statement
1. WAP to check da y of a wik whether it's Mon, Tue, Wed.....or Sun.

2. WAP to check da month of a yr whether it's Jan.......Dec.

3. Wap to print da grade of a student in an academic session as per as

following rules :-

Avg marks Grade
80 to 100 Honours
60 to 79 1st Div
50 to 59 2nd Div
40 to 49 3rd Div
00 to 39 Fail

4. Wap to find da largest amung 3 no.s.

5. An electric power distribution company charge its domestic consumers

as follows :-

Consumption Unit Rate of Charge
000 to 200 Rs 0.5 /unit
201 to 400 Rs 100 + Rs 0.65 /unit excess of 200 unit
401 to 600 Rs 230 + Rs 0.8/unit excess of 400 unit
600 & above Rs 390 + Rs 1/unit excess of 600 unit

Da prog read da customers no. & power consumed & print da amt 2 b paid

by da customer.

6. WAP to create da equivalent of a 4-function calculator. Da prog

requires da user to enter 2 no. & an operator. It then carries out da

specified arithemetical operation : addition, subtraction,

multiplication or division of da 2 no.


Plz help gimme da code.

Hop u ppl 'll help

Anindya
 

abhra_life

Broken In
4.WAp to find the largest no of 3

void main()
{
int a,b,c;
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<a;
}
else
{
if(b>c)
cout<<b;
else
cout<<c;
}
}
 

anubhav_har

In the zone
1)Day of the week
#include<iostream.h>
#include<conio.h>
void main()
{
int day;
cout<<"\nEnter wihcih day of the week (1-7):";
cin>>day;
if(day<1 || day>7)
cout<<"\nWrong day entered,.,,";
else if(day==1)
cout<<"\nMonday";
else if(day==2)
cout<<"\nTuesday";
else if(day==3)
cout<<"\nWednesday";
else if(day==4)
cout<<"\nThursday";
else if(day==5)
cout<<"\nFriday";
else if(day==6)
cout<<"\nSaturday";
else if(day==7)
cout<<"\nSunday";
}
2) For month of the year
just change day<1 and day>12 in the above program
if 1 then january...
12 then december...

3)Grade of student...
#include<iostream.h>
#include<conio.h>
void main()
{
float avg;
cout<<"\nEnter avg marks(0-100%):";
cin>>avg;
if(avg<0 || avg>100)
cout<<"\nCannot be less than 0 or more than 100,.,,";
else if(avg>=0 && avg<=39)
cout<<"\nFailed....";
else if(avg>=40 && avg<=49)
cout<<"\nThird division";
else if(avg>=50 && avg<=59)
cout<<"\nSecond division";
else if(avg>=60 && avg<=79)
cout<<"\nFirst division";
else if(avg>=80 && avg<=100)
cout<<"\nHonours";
}
4)Already done by abhra_life
5)Electric bill
#include<iostream.h>
#include<conio.h>
void main()
{
int custno;
float avg;
double total;
cout<<"\nEnter customer no:";
cin>>custno;
cout<<"\nEnter no of units:";
cin>>avg;
if(avg>=0 && avg<=200)
total=avg*0.50;
else if(avg>=201 && avg<=400)
total=100+((avg-200)*0.65);
else if(avg>=401 && avg<=600)
total=230+((avg-400)*0.80);
else if(avg>=601)
total=390+((avg-600)*1.00);
cout<<"\nTotal bill for customer no "<<custno<<" for "<<avg<<" units is "<<total;
cout<<endl;
}
6)4 function calculator...
#include<iostream.h>
#include<conio.h>
void main()
{
int opt;
double n1,n2,x;
cout<<"\nEnter:\n1. for addition\n2. for subtraction\n3. for multiplication\n4. for division\n";
cin>>opt;
if(opt<1 || opt>4)
{
cout<<"\nWrong option...";
}
else
{
cout<<"\nEnter number 1:";
cin>>n1;
cout<<"\nEnter number 2:";
cin>>n2;
if(opt==1)
{
x=n1+n2;
cout<<"\nThe sum of "<<n1<<" and "<<n2<<" is "<<x;
}
else if(opt==2)
{
x=n1-n2;
cout<<"\nThe difference of "<<n1<<" and "<<n2<<" is "<<x;
}
else if(opt==3)
{
x=n1*n2;
cout<<"\nThe product of "<<n1<<" and "<<n2<<" is "<<x;
}
else if(opt==4)
{
x=n1/n2;
cout<<"\nThe quotient of "<<n1<<" and "<<n2<<" is "<<x;
}
}
}
 

abhra_life

Broken In
A better way of doing 1 & 2 :-

void main()
{
int d;
cout<<"Enter day :: ";
cin>>d;
switch(day)
{
case 1:cout<<"Monday";
break;
case 2:cout<<"Tuesday";
break;
.
.
.
.
.
case 7:cout<<"Sunday";
break;
default:cout<<"Wrong Entry";
}
}
 

ashu888ashu888

Core i7 (nehalem) Owner
Hey Abhra ,buddy in ur program , the d shud be replaced by the variable name "day" as ur using this variable in the Switch case...:)
void main()
{
int d;
cout<<"Enter day :: ";
cin>>d;
switch(day) //change it to day buddy..
{
case 1:cout<<"Monday";
break;
case 2:cout<<"Tuesday";
break;
.
.
.
.
.
case 7:cout<<"Sunday";
break;
default:cout<<"Wrong Entry";
}
}
 

abhra_life

Broken In
ashu888ashu888 said:
Hey Abhra ,buddy in ur program , the d shud be replaced by the variable name "day" as ur using this variable in the Switch case...:)
void main()
{
int d;
cout<<"Enter day :: ";
cin>>d;
switch(day) //change it to day buddy..
{
case 1:cout<<"Monday";
break;
case 2:cout<<"Tuesday";
break;
.
.
.
.
.
case 7:cout<<"Sunday";
break;
default:cout<<"Wrong Entry";
}
}


sorry fo rth error
change the switch(day) to switch(d)
 

The Incredible

Ambassador of Buzz
Hey!

Guys thanks for very very much helpful reply.

BTW dear abhra_life

i mentioned that da programs r 2 be made with da use of else - if statement.

abt switch. its da last part of my QB


Here it is.

Use of switch statement


1. WAP to check day of a week depending upon user's choice such as (1- Mon, 2- Tue, 3- Wed ........ , 7-Sun & other no. day doesn't exist ).

Note :- is it wat abhra_life gave and ashu corrected? I don't think so.


2. WAP to check month of a yr depending upon user's choice. like da above one.


3. WAP to calculate area of a circle, rectangle & triangle depending upon user's choice.
such as ( if user wants to cal da area of a circle then calculate that, if user wants 2 cal da area of rect then cal that or if user wanna cal da area of tri then do that).


Hey anubhav!

i understud how 2 use if, if-else, but can't understand da use of else-if also wat's da use of

switch?

i know there's a tut but i want it in a familiar lang, in short. very short.


Thanks every1 once again.

Trust me i'll read da tut as i get time.

also i've written all this offline not while being online.



BYE

ANINDYA
 

Ashis

In the zone
Its hard to believe; People are talking C++ at digit forum!

Great!
Keep It Up! :cool:

Does any one knows PHP very Well or at least fundamentals ??? :wink:
 

anubhav_har

In the zone
hey incredible difference b/w if else and else if
Code:
if else syntax

if(condition)
{
	statement1;
	statement2;
}
else
{
	statement1;
	statement2;
}

else if syntax	

if(condition1)
{
	statement1;
	statement2;
}
else if(condition2)
{
	statement1;
	statement2;
}
else if(condition3)
{
	statement1;
	statement2;
}

So if else is used when you have to check for only one conidition...
and else if is used where there are multiple condition checks....
Will post the codes soon...
 

anubhav_har

In the zone
WAP days check
#include<iostream.h>
void main()
{
int day;
cout<<"Enter day :: ";
cin>>day;
switch(day)
{
case 1:
cout<<"Monday";
break;
case 2:
cout<<"Tuesday";
break;
case 3:
cout<<"Wednesday";
break;
case 4:
cout<<"Thursday";
break;
case 5:
cout<<"Friday";
break;
case 6:
cout<<"Saturday";
break;
case 7:
cout<<"Sunday";
break;
default:
cout<<"Wrong Entry";
break;
}
}

Month of the year using switch is same as the above program just add extra cases till twelve and change day names to months..

Area program
#include<iostream.h>
void main()
{
int choice;
double rad,len,width,ba,hei;
cout<<"Enter choice::\n1. for area of circle\n2. for rectangle\n3. for traingle\nAny other to quit\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter radius of circle:";
cin>>rad;
cout<<"\nThe area of circle is "<<3.14*rad*rad;
break;
case 2:
cout<<"\nEnter length of rectangle:";
cin>>len;
cout<<"\nEnter width of rectangle:";
cin>>width;
cout<<"\nThe area of rectangle is "<<len*width;
break;
case 3:
cout<<"\nEnter base of triangle:";
cin>>ba;
cout<<"\nEnter height of triangle:";
cin>>hei;
cout<<"\nThe area of triangle is "<<ba*hei*0.50;
break;
default:
cout<<"Thanks for using...";
break;
}
}
 

The Incredible

Ambassador of Buzz
Thanks anubhav.

THANKS A TRILLION!!!

BTW if possible tel me da use of switch n how does it works.

i understud da use of else-if.

Thanks once again.

Bye.
 

mohit sharma

Journeyman
well anubhav i think till now ur problem must had been solve .

and keep moving ahead in life .

best of luck !
and remember ' DIGIT FORUM ke saath rahoge to aise hi aish karoge '.

here u will get many elder brother's precious advice !
 

QwertyManiac

Commander in Chief
a switch statement is a shortened and wiser use of a lot of nested else-if's

It works this way...

switch(choice)
{
case 1:
// When u enter the no. 1 and press enter this is executed.
cout<<"\nEnter radius of circle:";
cin>>rad;
cout<<"\nThe area of circle is "<<3.14*rad*rad;
break;
case 2:
// When u enter the no. 2 and press enter this is executed.
cout<<"\nEnter length of rectangle:";
cin>>len;
cout<<"\nEnter width of rectangle:";
cin>>width;
cout<<"\nThe area of rectangle is "<<len*width;
break;
case 3:
// When u enter the no. 2 and press enter this is executed.
cout<<"\nEnter base of triangle:";
cin>>ba;
cout<<"\nEnter height of triangle:";
cin>>hei;
cout<<"\nThe area of triangle is "<<ba*hei*0.50;
break;
default:
//This statrment shows up if u dont enter a valid number / after the main cases ^^ have been executed.
cout<<"Thanks for using...";
break;//these break statements r perhaps the most vital part of the switch statements.It means that after executing the code of the case specified, stop execution and jump either to the outside/default of the switch statement.
//try not putting these break statements and see what u will get in difference to with it, then u will understand it better.

}
 

anubhav_har

In the zone
mohit sharma said:
well anubhav i think till now ur problem must had been solve .

and keep moving ahead in life .

best of luck !
and remember ' DIGIT FORUM ke saath rahoge to aise hi aish karoge '.

here u will get many elder brother's precious advice !

hey man i did not have problems... incredible had problems and i waS SOLVING EM..
 

The Incredible

Ambassador of Buzz
correct me was havin probs.

BTW

Thanks every1 for ur so valuable help.

But yet i've not got da code of a program

i'm mentioning it below.

Use of if-else statement:-

6. WAP to read 4 values a, b, c & d from da terminal & calculate da ratio of (a+b) to (c-d) & print da result, if (c-d) is not equal to zero.

Thanks every1 once again.

can't write mor gonna prepare maths for 2morrow.

Rest Assured

Anindya
 

QwertyManiac

Commander in Chief
Code:
#include<iostream.h>
void main ()
{
int a,b,c,d,r1,r2,ratio;
cout<<"\nEnter a";
cin>>a;
cout<<"\nEnter b";
cin>>b;
cout<<"\nEnter c";
cin>>c;
cout<<"\nEnter d";
cin>>d;
r1=a+b;
r2=c-d;
{
if (r2<=0)
{
cout<<"\n c-d is zero, cant continue";
}
else
{
ratio=r1/r2;
cout<<"the ratio is "
cout<<ratio;
}
}

Hope this is right :oops: :d :?:
 

anubhav_har

In the zone
ya it is fine... just check that if you dont want a negative answer or sometinhg like that then change in the line
if (r2==0) you can change it to... if(r2<=0)/// just it... otherway the program is completely fine...
 
Top Bottom