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

Need help with project

Ok I think I am close but I know I am stumped. I need to code a program so it displays the color of the item whose item number is entered by the user. All item numbers contain exactly five characters. All items are available in four colors: blue, green, red, and white. The third character in the item number indicates the item’s color, as follows:

Character Color
B or b Blue
G or g Green
R or r Red
W or w White

For example, if the user enters 12b45, the program should display the word “Blue” on the screen. If the item number does not contain exactly five characters, or if the third character is not one of the characters listed above, the program should display an appropriate message on the screen.

I have it where if the users enters an item number less than 5 digits they are prompted to re-enter. I could not figure out how to prompt for the 3 digit as well. Here is what I have so far.

Expand|Select|Wrap|Line Numbers
  1. /*
  2. Lab 12
  3. Displays the color of an item
  4. */
  5.  
  6. #include <iostream>
  7. #include <string>
  8. #include <algorithm>
  9.  
  10. using std::cout;
  11. using std::cin;
  12. using std::endl;
  13. using std::string;
  14.  
  15. int main()
  16. {
  17.       //declare variables
  18.       string itemNumber       = "";
  19.       string letter           = "";
  20.       int location            = 0;
  21.  
  22.       //get the item number
  23.       {
  24.             cout << "Please enter a five-digit item number: ";
  25.             getline(cin, itemNumber);
  26.             //location = int(itemNumber.find("x", 3));
  27.             //if (location >= 0)
  28.             if(itemNumber.length() != 5)
  29.             {
  30.                   cout << "Sorry, item number must be 5-digits and the 3-digit must be g, b, r or w: ";
  31.                   getline(cin, itemNumber);
  32.                   transform(itemNumber.begin(), itemNumber.end(), itemNumber.begin(), toupper);
  33.                   cout << "Item number " << itemNumber << " is " << endl;
  34.             }
  35.             else
  36.             {
  37.                   transform(itemNumber.begin(), itemNumber.end(), itemNumber.begin(), toupper);
  38.                   cout << "Item number " << itemNumber << " is " << endl;
  39.         } //end if
  40.       }
  41.  
  42. }     //end main function
  43.  
Any and all help would be greatly appreciated.
Nov 27 '06 #1
2 1604
If you're using c++ (I have no experience in programming with c), the algorithm for reading integers and characters will favor you.

For example, look at this code fragment I made:
Expand|Select|Wrap|Line Numbers
  1. {
  2. int first_set_of_integers, second_set_of_integers;
  3. char color;
  4.  
  5. cout << "Enter the color combination thing: ";
  6.  
  7. cin >> first_set_of_integers;
  8. cin >> color;
  9. cin >> second_set_of_integers;
  10. }
  11.  
The output will be something like:

Enter the color combination thing: 12b45

first_set_of_integers will be set to 12
color will be set to 'b'
and second_set_of_integers will be set to 45

:) Hope ya can use it!
Nov 27 '06 #2
rydo25
1
i typed all that into dev c++ but i never got a color or name of a color to show up. how do you get it to tell you what color code you entered? i dont much about this stuff but it is all very interesting
Jul 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Mark | last post by:
Hi, For the last 2 years I've been developing vehicle tracking/telemetric software for a company as a self employed individual. The project is quiet big, and is going to be there flagship...
3
by: Andrej Hristoliubov | last post by:
I am the best c++ programmer in the whole wide world. Trust ME! My reference is Victor Bazarov,Valentin Samko,Alf P.Steinbach( Me and Alf actually intern together at Microsoft), and Bjarne...
2
by: Susan Bricker | last post by:
Greetings Experts ... I have a routine that is invoked when a command button is clicked. The button is located in a form that is tied to a table of Project records. Each Project Record has 0 to...
10
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
6
by: sivashankar | last post by:
hello experts -can any one give me some module to do in asp.net -if u give me the description i will give u with free of cost,since am new now am in my final semester of MCA,just give me some...
7
by: moondaddy | last post by:
I want to create a public enum that can be used throughout a project. I created an enum like this in a module: Public Enum ParentType Project = 0 Stage = 1 VIP = 2 Func = 3 Equipment = 4...
5
by: info | last post by:
Hi! Please be patient with a newbie... I use DevC++. I've found and compiled succefully various openGL examples. Before build the application, I link the project with static libs, like, in...
8
by: Brett Romero | last post by:
I have this situation: myEXE <needs< DerivedClass <which needs< BaseClass Meaning, myEXE is using a type defined in DerivedClass, which inherits from BaseClass. I include a reference to...
10
by: Frank | last post by:
I've done this a few times. In a solution I have a project, Say P1, and need another project that will contain much code that is similar to that of P1. I hope no one gets hung up on why I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.