473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with loop in random characters generation

3
I cant get my summary_Count function to work i figured it out that it stops working on the for loop part here

Expand|Select|Wrap|Line Numbers
  1. void summary_Count(char random[], int n)
  2. {
  3.  
  4.      int t=0;
  5.      int count[26]={0};
  6.  
  7.      for(int a=0; a<=25; a++)
  8.      {
  9.      for(char i=97; char i=122; i++)
  10.      {
  11.      for(int j=0; j<=n; j++)
  12.         {       
  13.          if (random[j]=i) count[a]++;
  14.         }}}    
  15.  
  16.  
  17.    cout<<"\nSummary for the characters:"<<endl<<endl;
  18.    for(char ch='a';ch<='z';ch++)
  19.    {
  20.    cout<<ch<<" = "<<count[t] <<endl;
  21.    t++;
  22.    }
  23.  
  24. }
  25.  
The overall goal is to generate random charcters then count them and print how many a,b,c...ect. I made that for loop to count my letters but when i run it it stops right when it reaches the for loops. My full code is here its kind of mess though.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. #include <cstdlib>
  5. #include <stdio.h>
  6. #include <ctype.h>
  7.  
  8. using namespace std;
  9. void parameters(int& seed,int& n);
  10. char getChar(int seed);
  11. void printCharcter(char random[],int n);
  12. void summary_Count(char random[], int n);
  13. int main()
  14. {
  15. bool repeat=true;  
  16. int seed; 
  17. int n;
  18. char random[n];
  19. char again;
  20. srand(seed);
  21. do{
  22. parameters(seed, n); 
  23.  
  24. for(int i=0; i<n; i++)
  25. {
  26. random[i]=getChar(seed);
  27. }
  28. printCharcter(random,n);
  29.  
  30. for(int j = 0; random[j] != '\0'; j++)
  31. {
  32. random[j] = tolower(random[j]);
  33. }
  34.  
  35. summary_Count(random, n);
  36.  
  37.  
  38. cout<<"\nDo you wish to try again? (Y/N) ";
  39. cin >> again;
  40. cout<<endl;
  41. if (again == 'n' || again == 'N') repeat=false ;
  42. else repeat=true ;
  43. }
  44. while(repeat==true);
  45.  
  46.  
  47.  system("PAUSE");
  48.  return 0;
  49. }
  50.  
  51. void parameters(int& seed,int& n)
  52. {
  53.  
  54.    cout<<"Enter a seed number:";
  55.    cin>>seed;
  56.    cout<<"\nHow many charcters do you want generated:";
  57.    cin>>n;
  58.    if(n>100)
  59.    {
  60.         cout<<"Invlaid input, enter again"<<endl;
  61.         cin>>n;
  62.    }
  63.  
  64.         cout<<endl;
  65.  
  66. }
  67. char getChar(int seed)
  68. {
  69.  
  70.    char random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"[rand() % 52];
  71.    return random; 
  72. }
  73. void printCharcter(char random[],int n)
  74. {
  75.      cout<<"Charcters generated are:"<<endl;
  76.      for(int i=0; i<n; i++)
  77.      { 
  78.        if (i% 10== 0) cout<<endl;
  79.        cout<<random[i];
  80.  
  81.      }
  82. }
  83. void summary_Count(char random[], int n)
  84. {
  85.  
  86.      int t=0;
  87.      int count[26]={0};
  88.  
  89.      for(int a=0; a<=25; a++)
  90.      {
  91.      for(char i=97; char i=122; i++)
  92.      {
  93.      for(int j=0; j<=n; j++)
  94.         {       
  95.          if (random[j]=i) count[a]++;
  96.         }}}    
  97.  
  98.  
  99.    cout<<"\nSummary for the characters:"<<endl<<endl;
  100.    for(char ch='a';ch<='z';ch++)
  101.    {
  102.    cout<<ch<<" = "<<count[t] <<endl;
  103.    t++;
  104.    }
  105.  
  106. }
  107.  
Oct 17 '11 #1
4 2362
ai123
3
for the if statement i forgot the second = but that still didn't fix my problem
Oct 17 '11 #2
johny10151981
1,059 1GB
I am little confused.. does it compile at all???

anyway your for loop seems endless fix your forloop in the first code block. On line 9 the condition is always true
Oct 17 '11 #3
ai123
3
oh cant believe i didnt see that yea it compiles but it dosent work,
Oct 17 '11 #4
Rabbit
12,516 Expert Mod 8TB
You really only need one loop. Just loop through the random array and increment the count index based on the ascii value.
Oct 17 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: whisper | last post by:
Medium/small site with mod_python and sqllite or mySQL running Python 2.3.3 or later on Apache 2.x. I can do the python and CGI, but might need a _little_ hand holding for the rest. Will also...
2
by: ratedr1 | last post by:
I am currently trying to label rings (jewelry). They make specialized tags (shaped like a butterfly, barbell, dumbell, etc) for this purpose, the label goes through the ring, and then the ends...
2
by: Chad A. Beckner | last post by:
Hey all, I have a ASP .NET webpage which contains several panels. When I click a button on the first "panel" page, it postsback to the same page, and I switch the visibility of the panels...
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
1
by: Massimo Bonanni | last post by:
Hi, I try to implement ASAP protocol in my web service, but I find a very hard problem. I define my SOAP Header: public class Request : SoapHeader {
4
by: briggsie2006 | last post by:
I need to write a program called wc.py. It promts the user to input a filename and outputs the number of lines, words, and, characters in the file. I really need help on this because I don't know...
5
by: Karthik D V | last post by:
Hello All, I have a table like this ID CHARACTER ----------- --------- 1 A 2 A 3 B 4 B
5
by: fortwaynemarketplace | last post by:
Need these two scripts; 1. (Action) script for email (outlook express or...) to come up in .swf enviroment. I have created a button (email us), need action scritps to send/recevie an email. ....
2
by: Alenik1989 | last post by:
I wrote this code, but I'm not able to test it because im getting 3 errors. So I'm not sure that this code will work properly or not!!! the code in #include <stdio.h> #include <stdlib.h> int...
2
by: Coxmg | last post by:
Here is the code, ACCESS 2007: Hello, I have a dialog box that opens on a form that lets the user browse files. I simply want to limit it to Folders, how can I do that? Need ASAP. Thanks. ACCESS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.