GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Dec-2008, 21:52
MMac1218 MMac1218 is offline
New Member
 
Join Date: Dec 2008
Posts: 2
MMac1218 is on a distinguished road

Error C2784: 'bool std:perator >(const std::basic_string<_Elem,_Traits,_Alloc>


Please help, I dont know what I am doing wrong and I been messing with this for 3 hours now.
Keep getting
Code:
error C2784: 'bool std:perator >(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'int'

CPP / C++ / C Code:
/*	Write a program that allows the user to enter foods and their calories. Allow for UP TO
	100 entries, although the actual number may be way less. When the user types "done"
	then stop asking for new entries. Prompt the user for a food item; when entered, search
	the list and display the item and the number of calories. If the item is not found, indicate
	that. Stop prompting for items to search for when the user enters "done". Use the
	following screen shots as a guide.

*/

#include <iostream>
#include <string>
using namespace std;
int main()
{
string food[101];
int calories[101];
int a = -1;
do
{
a++;
cout << "Enter a menu item (enter 'done' when finished): ";
getline(cin, food[a]);
if (food[a] != "done")
{
cout << "Enter the number of calories: ";
cin >> calories[a];
cin.ignore();
}
} while (food[a] != "done");
for (int x = 1; x < a; x++)
{
for (int y = 0; y < a-1; y++)
{
if (food[y] > calories[x])
{
string tmpfood = food[x];
int tmpcalories = calories[x];
food[x] = food[y];
calories[x] = calories[y];
food[y] = tmpfood;
calories[y] = tmpcalories;
}
}
}
for (int b = 0; b < a; b++)
{
cout << food[b] << " has " << calories[b] <<
" calories." << endl;
}
}
Attached Images
File Type: pdf Assignment_28_and_29_Final_Assignment.pdf (31.6 KB, 19 views)
Last edited by admin : 04-Dec-2008 at 23:34. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 04-Dec-2008, 23:04
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: Please help


CPP / C++ / C Code:
if (food[y] > calories[x])
You're checking if a string is greater than an int. Thinking about it for a second, does that make sense? What are you trying to do at that line?
  #3  
Old 05-Dec-2008, 03:53
MMac1218 MMac1218 is offline
New Member
 
Join Date: Dec 2008
Posts: 2
MMac1218 is on a distinguished road

Re: Error C2784: 'bool std:perator >(const std::basic_string<_Elem,_Traits,_Alloc>


so do I change it to an = sign? I dont get it
  #4  
Old 05-Dec-2008, 07:31
nostaque nostaque is offline
New Member
 
Join Date: Oct 2008
Posts: 19
nostaque will become famous soon enough

Re: Error C2784: 'bool std:perator >(const std::basic_string<_Elem,_Traits,_Alloc>


Quote:
Originally Posted by MMac1218
so do I change it to an = sign? I dont get it

what he said is: you can compare orange to orange ONLY
can you say 100 POUND person is greater than 80 YEAR OLD one?
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:55.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.