Help the PSP 3D community grow! Vote for us below:


| | Development Center - Learn the basics of coding or talk about advanced coding techniques with other developers. |
Welcome to PSP3D.com - Sony PlayStation Portable News, Homebrew, Hacks, Reviews, Videos, Mods, Forums!
You are currently viewing our website as a guest, which gives you limited access to reply and interact to discussions and other members. By joining our free community, you will be able to post topics in the forums, communicate privately with other members, vote in polls, and access many other special features.
Registration is fast, simple, and absolutely free so join our community today!
| 
08-30-2007, 02:03 PM
| | Moderator
My Mood: | | Join Date: Jun 2006 Location: Iacon, Cybertron Age: 20
Posts: 2,385
Points: 440,666.30 Donate | | | Need help with my code! I am trying to learn C++ and I am trying to make an app where it has you type in two names and then it says name1 has a crush on name2. But my code isn't working right. Can you guys take a look at it and help me out? Code: #include
using namespace std;
int main()
{
int name1;
int name2;
cout<<"Type a name: ";
cin>> name1;
cout<<"Type another name: ";
cin>> name2;
cout<<"Guess what?" << name1 <<"has a crush on "<< name2 <<"\n";
return 0;
} | 
08-30-2007, 03:14 PM
| | PSP3D's Strangest Member
My Mood: | | Join Date: Nov 2005 Location: Ca$hville Age: 16
Posts: 775
Points: 3.44 Donate | | | you need a cin.get(); or cin.ignore(); i think
__________________ Think outside the cubical triangle wilhel1812 is my hero!
Join my site! http://uberforumz.com
Thanks to pspkillsds for 250 points!
Thanks to zzaz3 for 59,000 points!  | 
08-30-2007, 03:39 PM
| | Moderator
My Mood: | | Join Date: Jun 2006 Location: Iacon, Cybertron Age: 20
Posts: 2,385
Points: 440,666.30 Donate | | I had those in, but it didn't make a difference. What do those do any way, I just copied code from a tutorial site and messed around with it.
EDIT: I added in the cin.ignore(); codes and the cin.get(); too. It will compile with and with out them, but when I go to use the program it just displays this: Code: Last login: Thu Aug 30 14:46:33 on ttyp1
Welcome to Darwin!
172:~ jeff$ /Users/jeff/Desktop/programs/enter/enter1; exit
Type a name: jeff
Type another name: Guess what?-1880832560has a crush on -1073743208
logout
[Process completed] I am opening this through Terminal (on OS X) and compiling it in the same app.
Here is the source now: Code: #include
using namespace std;
int main()
{
int name1;
int name2;
cout<<"Type a name: ";
cin>> name1;
cin.ignore();
cout<<"Type another name: ";
cin>> name2;
cin.ignore();
cout<<"Guess what?" << name1 <<"has a crush on "<< name2 <<"\n";
cin.get();
return 0;
}
Last edited by dq9 : 08-30-2007 at 03:50 PM.
| 
08-30-2007, 04:35 PM
| | Senior Member | | Join Date: Dec 2005 Location: flash0:/vsh/resource
Posts: 1,037
Points: 4.88 Donate | | | p00p . | 
08-30-2007, 07:37 PM
| | PSP3D's Strangest Member
My Mood: | | Join Date: Nov 2005 Location: Ca$hville Age: 16
Posts: 775
Points: 3.44 Donate | | | try changeing the variables to 1 and 2
__________________ Think outside the cubical triangle wilhel1812 is my hero!
Join my site! http://uberforumz.com
Thanks to pspkillsds for 250 points!
Thanks to zzaz3 for 59,000 points!  | 
08-30-2007, 08:45 PM
| | Moderator
My Mood: | | Join Date: Jun 2006 Location: Iacon, Cybertron Age: 20
Posts: 2,385
Points: 440,666.30 Donate | | Code: 172:~/Desktop/programs/enter jeff$ g++ -o enter1 enter1.cpp
enter1.cpp: In function 'int main()':
enter1.cpp:12: error: expected unqualified-id before numeric constant
enter1.cpp:13: error: expected unqualified-id before numeric constant
enter1.cpp:16: error: ambiguous overload for 'operator>>' in 'std::cin >> 1'
/usr/include/c++/4.0.0/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits]
/usr/include/c++/4.0.0/istream:134: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits]
/usr/include/c++/4.0.0/istream:137: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits]
/usr/include/c++/4.0.0/istream:230: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits]
enter1.cpp:19: error: ambiguous overload for 'operator>>' in 'std::cin >> 2'
/usr/include/c++/4.0.0/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits]
/usr/include/c++/4.0.0/istream:134: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits]
/usr/include/c++/4.0.0/istream:137: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits]
/usr/include/c++/4.0.0/istream:230: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits] This is what I for when I tried to compile it.
Here is my source code now: Code: #include
using namespace std;
int main()
{
int 1;
int 2;
cout<<"Type a name: ";
cin>> 1;
cin.ignore();
cout<<"Type another name: ";
cin>> 2;
cin.ignore();
cout<<"Guess what?" << 1 <<"has a crush on "<< 2 <<"\n";
cin.get();
return 0;
} Are my arrows pointing the right way in the Code: cout<<"Guess what?" << 1 <<"has a crush on "<< 2 <<"\n"; line? | 
08-31-2007, 01:13 AM
| | PSP3D's Strangest Member
My Mood: | | Join Date: Nov 2005 Location: Ca$hville Age: 16
Posts: 775
Points: 3.44 Donate | | | think i figured it out- you need a char because you cant store letters in variables
__________________ Think outside the cubical triangle wilhel1812 is my hero!
Join my site! http://uberforumz.com
Thanks to pspkillsds for 250 points!
Thanks to zzaz3 for 59,000 points! 
Last edited by iamstrange14 : 08-31-2007 at 01:15 AM.
| 
08-31-2007, 11:25 AM
| | Senior Member | | Join Date: Dec 2005 Location: flash0:/vsh/resource
Posts: 1,037
Points: 4.88 Donate | | | I know my reply helped alot. | 
08-31-2007, 01:41 PM
| | Moderator
My Mood: | | Join Date: Jun 2006 Location: Iacon, Cybertron Age: 20
Posts: 2,385
Points: 440,666.30 Donate | | Indeed it did pspkillsds.
iamstrange14: What is a char? Don't forget, I am still learning and don't know to much yet. And thanks for all of your help so far.
EDIT: my girlfriend came to the rescue. Here is my new code (that works): Code: #include
#include
using namespace std;
int main()
{
string name1;
string name2;
cout<<"Type a name: ";
cin>>name1;
cin.ignore();
cout<<"Type another name: ";
cin>> name2;
cin.ignore();
cout<<"Guess what? " << name1 <<" has a crush on "<< name2 <<"\n";
cin.get();
return 0;
}
Last edited by dq9 : 08-31-2007 at 06:20 PM.
| 
08-31-2007, 06:52 PM
| | PSP3D's Strangest Member
My Mood: | | Join Date: Nov 2005 Location: Ca$hville Age: 16
Posts: 775
Points: 3.44 Donate | | | so it looks like you left out an include and hads the .get's and .ignore's mixed up? i dont know too much either and i was still learning until i screwed up dev c++
__________________ Think outside the cubical triangle wilhel1812 is my hero!
Join my site! http://uberforumz.com
Thanks to pspkillsds for 250 points!
Thanks to zzaz3 for 59,000 points!  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is On Points Per Thread View: 0.00 Points Per Thread: 1.00 Points Per Reply: 0.10 | | | | |