Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 displaying guessed letters
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
signal_1001




PostPosted: Sun Jun 06, 2004 4:24 pm   Post subject: displaying guessed letters

Hey there, Help right now would be really appreciated! I'm getting very frustrated with this program. I want to output all the letters that have been guessed, but the only cin variable i have is guess and it just loops through asking for guess everytime. i've tried
code:
char blankLetters[60];
                char lettersGuessed[60]="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
                for(int y=0; y<=strlen(lettersGuessed); y++)
                {
                        if(lettersGuessed[y]<=91 && lettersGuessed[y]>=64 || lettersGuessed[y]>=96 && lettersGuessed[y]<=123)
                        {
                                blankLetters[y]=' ';
                        }
                        else blankLetters[y]=lettersGuessed[y];
                }
for(y=0; y<=strlen(lettersGuessed); y++)
                                        {       
                                                if(lettersGuessed[y]==guess)//guess being the letter input
                                                {
                                                        blankLetters[y]=lettersGuessed[y];
                                                }
                                        }

but it didnt work so i dont know what to do.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Mon Jun 07, 2004 9:50 am   Post subject: (No subject)

why dont you just output the letter that the user guessed right after he guess it?
wtd




PostPosted: Wed Jun 09, 2004 3:53 am   Post subject: (No subject)

code:
#include <iostream>
#include <vector>
#include <algorithm>

void print(char ch)
{
   std::cout << ch;
}

int main()
{
   std::vector<char> letters_guessed;
   char temp;
   for (int i = 0; i < 26; i++)
   {
      std::cin >> temp;
      letters_guessed.push_back(temp);
   }

   std::for_each(letters_guessed.begin(), letters_guessed.end(), print);
}
wtd




PostPosted: Tue Jun 15, 2004 3:32 am   Post subject: (No subject)

code:
(*
        And just because I have too much time on my hands...
        Read and report characters.
        file: rrarc.ml
        compile (on Windows) with: ocamlc rrarc.ml -o rrarc.exe
        run as: rrarc <number of characters>
*)

open List
open Array
open Sys

let default_value = 26;;

let rec read_chars n =
        let n = (abs n) in
                match n with
                0 -> []
                | _ -> let ch = (read_line ()).[0] in ch :: (read_chars (n - 1));;

let _ =
        let argv_len  = (Array.length Sys.argv) in
        let char_num  = (try (int_of_string Sys.argv.(1)) with _ -> default_value) in
        let char_list = (read_chars char_num) in
                List.map print_char char_list;;
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: