help for function problem

this is what the program is supposed to do:
ask user for 7 character item number. The 4th character denotes the color of the item. The program is to return the color. There needs to be a sentinal so the user can opt out, and there needs to be an error display if the item number is not 7 characters or there is no color character given for the 4th character. The colors are denoted by r, b, g, or w, which can also be given as upper case.
We are supposed to use functions to carry all this out, giving the prototypes, the definitions, and then properly calling the function into use in the main function. I have a lot of this coded, but am very much an amature and need help getting it to work. I am facing a deadline and need help!! Please. Thanks

this is what I have so far. Give me some suggestions on making this work.

#include <iostream>
#include <string>

using namespace std;

// INSERT YOUR FUNCTION PROTOTYPES HERE
char getColor();
void writeColor(char color);

int main()
{
// declare variables
string getColor();

// code the algorithm

writeColor(getColor());


}
system("pause");
return 0;
} //end of main function

// INSERT YOUR FUNCTION DEFINTIONS HERE

char GetColor()
{
while(true)
{
string itemNumber = "";
cout << "Enter item number (Q to quit): ";
getline(cin, itemNumber);

if (itemNumber == "q" || itemNumber == "Q") {
cout << " Thank you, goodbye." << endl;
break;
}

if (itemNumber.length() != 7) {
cout << "Invalid item number length." << endl;
continue;
}

void writeColor(char color)
{
char color = tolower(itemNumber.at(3));
cout << "Item you ordered is: " <<
}
first put code in between code block generated with the <> button second instead of system pause use cin.get(); third you can't have string getcolor(); because you are declaring a function not a variable. You don't need the () unless you want an array in which case you need a []. i could be wrong but you can't actually have while (true) you could try a var bool though. lastly you need a } after the last if statement
thank you for your reply, but I am not understanding the first input, and we are using the system pause in this class, so I have to stick with that. I also am not sure about the while(true) use in a function, but don't understand the var bool....I'm pretty hopeless on this.
sorry im writing quickly. Let me rephrase that

1)Put your code between code blocks generated with the <> button.
2)Okay with system ("pause"), but when you write your own code don't use because it takes up a lot of memory space
3)You have the char getColor() function and then said you declared string getColor() as a variable. If you meant that as a function you can't change its variable type in int main(). Also you don't even include its variable type when you are calling it. If you meant it as a variable you can't have the ().
4)Ill explain the while(true part in a sec)
5)After the write writeColor(getColor()) (in which you can't have the inner () there is a bracket. erase it
6)After the last if statement you need two }'s
7)char getColor() needs to return a character by using return (for example) 'a';
There is a variable type boolean or bool for short. Its values are true or false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

using namespace std;

int main()
{
int a;
bool b;

cout<<"Number:\n>";
cin>> a;

if(a > 100)
{
//note how i write true not "true"; it isn't a string
b = true;
}

if( a <= 100)
{
//bools other value
b = false;
}

//this says use this code if b is true (just write the variable name)
if(b)
{
cout<<"hi";
}

//this says use only if b is false (use a !)
if(!b)
{
cout<<"bye";
}
I'm sorry, but I am totally lost
on?
if just...
-all of it; compile it and tell me the errors it will give you
-bool; forget about it
#1)Put your code between code blocks generated with the <> button. This doesn't make sense to me.
I get that the while(true) won't work in the function. It is okay in the main function, but I was trying to accomplish what it was doing, giving the user an out (sentinel), and checking the length, in a function. Is there a way to do that?
I did put it back into the main function.

I am not getting out this is going to return the color from the user input, or accept either a lower or upper case letter for the 4th character.
first click edit on your original post then you should see a section that says format with a button that has <> in it. What appears: wrap your code around it
thank you for your patience. I guess that I'm just hopless at getting this. I appreciate your trying, but I'm no further and my deadline is in too short of time to figure this out.
im sorry my laptop died don't give up just slow down and try to understand what you are doing im sorry i couldn't help more
Topic archived. No new replies allowed.