hello...
Im new here n i hav question dat i am unable to complete...Plzz help me... -
#include<stdio.h>
-
-
int main(void)
-
-
{
-
int id, quantity, limit, order_limit, temp;
-
int ch, components, i, j,total,count;
-
-
limit = 5;
-
order_limit = 10;
-
int components_id[3];
-
int components_quantity[3],price;
-
-
-
-
-
int choice;
-
i=3;
-
while(i< order_limit)
-
{
-
printf("\n\n\n Available components in Unitar: \n\n");
-
printf("1. PC Components\n");
-
printf("2. Network\n");
-
printf("3. Exit\n\n\n");
-
-
}
-
-
printf("Press 1 to place order \nPress 2 to finish order: ");
-
scanf("%d",&ch);
-
printf("***************************\n\n");
-
printf(" -------------\n");
-
printf(" PC components\n");
-
printf(" -------------\n");
-
printf(" 1.Monitor:Rm100\n");
-
printf(" 2.Keyboard:Rm95\n");
-
printf(" 3.Mouse:Rm55\n");
-
printf(" 4.RAM:Rm237\n");
-
printf(" 5.Hard Disk:Rm76\n");
-
printf(" 6.ROM drive:RM189\n");
-
printf(" 7.Processor:Rm340\n");
-
printf(" 8.Others\n");
-
printf(" 9.Exit\n");
-
-
printf(" --------\n");
-
printf(" Neyworks\n");
-
printf(" --------\n");
-
-
if(ch == 1)
-
{
-
-
printf("\n enter component id: \n");
-
scanf("%d", &temp);
-
components_id[i] = temp;
-
-
if(components_id[i] > limit)
-
{
-
printf("\n invalid id entered...try again\n");
-
continue;
-
}
-
-
printf("\n enter quantity of component required: \n");
-
scanf("%d", &temp);
-
components_quantity[i] = temp;
-
-
printf("\n id: %d quantity: %d, i:%d \n", components_id[i], components_quantity[i], i);
-
i++;
-
printf("Total cost of each type of component is:%d\n");
-
price * components_quantity[i];
-
printf("%f",total);
-
-
}
-
-
else if(ch == 3)
-
break;
-
else
-
{
-
printf("\n invalid choice enterd...try again\n");
-
continue;
-
}
-
-
-
-
}
-
-
-
-
printf("\n\n\n ordered placed: \n");
-
for(j=0; j<i; j++)
-
printf("\n %d: component id:%d quantity: %d", j, components_id[i], components_quantity[i]);
-
-
-
-
getchar();
-
return 1;
-
}
-
these r my codes but its not really correct...im confused how to create switches in it....Can u plz help me with it?...
2 1576
I moved your question to its own thread; it is considered rude to hijack someone else's thread. I also fixed your [code] ... [/code] tags. One more bit of advice: write proper English, e.g. 'please' is not written 'plz'.
kind regards,
Jos (moderator)
@sweetipie
scanf will only change the value of ch if it finds that your input character stream is consistent with the format string. If you type 'A' rather than '5' then ch retains its previous value, which will cause you to repeat the action associated with the last time through the loop. @sweetipie
It would be a lot easier for potential helpers if you explained why this code is not satisfactory.
Are you getting compiler errors? If so, then cut and paste them into your post.
Is the program malfunctioning? If so, describe the erroneous behavior.
Do you want to refactor the program ... perhaps replace the if/elseif/else cascade with a switch statement? If so, describe your desires and constraints.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pgraeve |
last post by:
I am a convert from VB to C# so bear with me on this "conversion" question
C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
|
by: Cathleen C via DotNetMonster.com |
last post by:
I'm a semi-beginner with c# and am having a problem effectively implementing
a switch statement. I've created an asp.net app that runs a report depending
on which item was selected from a drop...
|
by: Macca |
last post by:
Hi,
I have a switch statement that has 5+ case statements. Each of these case
statements copies form one array to another. Rather than doing a separate
try..catch statement for each case...
|
by: Angel Of Death |
last post by:
I have a method. It takes some XML as a parameter. Depending on the
content of the XML it should create a specific object and call a KNOWN
method.
So: public void PersistXml(string XmlData){}
...
|
by: Phuff |
last post by:
Hey all, I need some direction help. I have a switch case statement
that is seemingly my only option right now, but its too large and not
easy to maintain the code. Here goes...
I have part...
|
by: |
last post by:
Is it fine to call another method from Switch?
Eg.
Switch (stringVar)
{
case ("a"):
somVar = "whatever";
Another_Method(); //call another method
return;
|
by: asadikhan |
last post by:
Hello,
I have a bit of a design issue around this application I am
developing, and I just want to run it through some of the brains out
here.
So I have a table called ErrorCheck which...
|
by: osward |
last post by:
Hello there,
I am using phpnuke 8.0 to build my website, knowing little on php programing.
I am assembling a module for my member which is basically cut and paste existing code section of...
|
by: Phillip B Oldham |
last post by:
What would be the optimal/pythonic way to subject an object to a
number of tests (based on the object's attributes) and redirect
program flow?
Say I had the following:
pets = {'name':...
|
by: Rohit |
last post by:
Hi,
I am working on a switch module which after reading voltage through a
port pin and caterogizing it into three ranges(open,low or high),
passes this range to a function switch_status() with...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |