Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple c++ Assignment coding

Posted on 2012-03-21
5
Medium Priority
?
402 Views
Last Modified: 2012-04-13
Hi Guys,

I was just wondering if I could get some help regarding my programming assignment. I'm new to programming and this subject being my elective, is making my brain explode. Any help will be greatly appreciated.

Firstly, Write a C++ program to display a menu of product choices on screen. The program
should operate continuously allowing the user to choose products until a quit option is
entered. Your program should use a switch statement to make a decision concerning which
product was entered and then display the name of that product.
Sample display:
Product list
1 Chainsaw
2 Whipper Snipper
3 Lawn Mower
4 Hedger
5 Brushcutter
6 Quit

I have written a code from a book and substituted my list for it, but it's giving me an error. My code is:

using namespace std;

int main()
{
int ch;
do{
cout<<"Product list\n1 Chainsaw\n2 Whipper Snipper\n3 Lawn Mower\n4 Hedger\n5 Brushcutter\n6 Quit"
cin>>ch;
switch(ch){
case 1: cout<<"Chainsaw";break;
case 2: cout<<"Whipper snipper";break;
case 3: cout<<"Lawn mower";break;
case 4: cout<<"Hedger";break;
case 5: cout<<"Brushcutter";break;
case 6: cout<<"Quit";exit(0);
default: cout<<"Invalid choice";break;
}
}while(ch!=6);
return 0;
}

Open in new window


Secondly, Write C++ code to do the following: Set up a record/structure to store products. Each product has a name, a model number and a price. Choose appropriate types for these fields. You program should contain a loop which allows entry via the keyboard of up to 10 products to be stored in an array. The loop can be stopped by entry of “quit” for the product name. Your program should include a function to then display all the product’s details after the entry loop has finished.

Thank you, all
0
Comment
Question by:tomatoes_program
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1500 total points
ID: 37750477
there should be a ; at the end of every statement.
you can declare cout and cin by including iostream
0
 

Author Comment

by:tomatoes_program
ID: 37750485
Thank you ozo!! I saw where I went wrong there but the error I'm getting is not a program error, but this:

"The NTVDM CPU has encountered an illegal instruction. CS:057b IP:0103 OP:63 6c 75 64 65 Choose 'Close' to terminate application."
0
 
LVL 35

Expert Comment

by:sarabande
ID: 37751754
i would make a rebuild (or build after clean) and would remove the exit(); statement (simply do a break; instead)

Sara
0
 
LVL 22

Expert Comment

by:ambience
ID: 37762482
By any chance are you using TurboC to compile your programs? The error suggests that your compiler is outputing an old DOS based 16 application? This has worked on some Windows versions but I havent seen any luck with latest Windows.

What compiler are you using?

I would suggest that you download and install Visual Studio Express (since you are already on Windows), which is free and quick and easy to setup and use.

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

Follow this tutorial to create a Console Based application and paste all your code there

http://msdn.microsoft.com/en-us/vstudio/Video/cc296427

Since you are a student you may also check and see if your institution has DreamSpark program (or contact Microsoft yourselves) and you can get even Professional versions free.
0
 

Author Comment

by:tomatoes_program
ID: 37840323
Thank you guys,

I worked it out on Dev-C++
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question