Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-14-2008, 10:50 AM
erabyss erabyss is offline
Newbie
 
Join Date: Sep 2008
Posts: 6
Rep Power: 0
erabyss is on a distinguished road
Default Funtion prototypes

I am very new to programming, and have been trying to figure out this problem for over an hour now. Can some one help me figure out what is wrong with my code?

This is a simple version of a funtion I am working on.

I want it to print "Unscramble the word: rnaooagk." Then check the players response against the answer.

The code compiles fine. But when I run it, nothing is printed to the screen.

My other question is:
Is it possible to setup my funtion with values for 2 strings?
(ex.)
string question(string word, string answer);

-This is my first time posting a quesion. I hope I made my problem clear.-

---------------------------------
Code:
#include 
#include 

using namespace std;

string reply; 
string answer = "kangaroo";
string word;
string question(string word);

int main()
{
string question("rnaooagk");
cin.get();
}

string question(string word)
{
do
{
cout << "Unscramble the word: " << word;
cin >> reply;
} while (reply != answer);
return reply;
}

Last edited by WingedPanther; 09-14-2008 at 01:58 PM. Reason: add code tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-14-2008, 12:10 PM
erabyss erabyss is offline
Newbie
 
Join Date: Sep 2008
Posts: 6
Rep Power: 0
erabyss is on a distinguished road
Default Re: Funtion prototypes

I think I got it. -code posted below-

If you know of a way to better write this piece of code, please share it with me. Thank you.

--------------------------------------
Code:
#include <iostream>
#include <string>

using namespace std;

string reply; 
string answer; // kangaroo rnaooagk
string word;
string word2;
string question(string word, string answer);

int main()
{
    string word2 = question("rnaooagk", "kangaroo");
    cin.get();
}

string question(string word, string answer)
{
    do
    {
     cout <<"Unscramble the word: "<< word << "\n";
cin >> reply;
    } while (reply != answer);
    return reply;
}

Last edited by WingedPanther; 09-14-2008 at 01:59 PM. Reason: add code tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-14-2008, 02:01 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: Funtion prototypes

Technically, your variable declarations should be inside your main/question function (as appropriate). As they are now, they are global variables, and passing them to the function doesn't do anything useful.

Also, please use code tags when writing code (you can press the # icon to get them).
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-14-2008, 02:05 PM
erabyss erabyss is offline
Newbie
 
Join Date: Sep 2008
Posts: 6
Rep Power: 0
erabyss is on a distinguished road
Default Re: Funtion prototypes

Thank you. I cant believe I forgot to limit the scope like that. I will fix that in my game now.

Forgive me for not using the proper tags. I didnt know it was there.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
c++, function, prototype, string



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 02:23 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads