943,963 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1783
  • C++ RSS
Nov 30th, 2004
0

Can Someone Tell me why my program does not run

Expand Post »
It is error free but it just doesnt cout for the user to continue or discontinue and it does now stop

C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. #include "simmons.h"
  4. #include <fstream.h>
  5.  
  6. const int MAXCHARS = 500;
  7. char st_line[MAXCHARS];
  8. char ch_option;
  9. int i_va;
  10. int i_ve;
  11. int i_vi;
  12. int i_vo;
  13. int i_vu;
  14. int i_letters = 0;
  15. int i_count = 1;
  16. int x = 0;
  17. int i_vowel = 0;
  18. char ch_char;
  19.  
  20. void hope();
  21. void vowels();
  22. void letter();
  23. void mike();
  24.  
  25. void main()
  26. {
  27. ifstream HopeData;
  28. HopeData.open("getdata");
  29. ofstream MikeData;
  30. MikeData.open("putdata");
  31.  
  32. if(HopeData.fail())
  33. {
  34. cout << "\n\nFile not successfully opened\n\n";
  35. }
  36. else
  37. {
  38. cout << "\n\nFile successfully opened\n\n";
  39. }
  40.  
  41. hope();
  42. while(st_line[x] != '\0');
  43. HopeData >> st_line;
  44. cin.get();
  45. do{
  46. vowels();
  47. letter();
  48. }while(ch_option != 'y');
  49. mike();
  50.  
  51.  
  52. cout << "\n\nDo you want to continue(Y/N)? ";
  53. cin.get(ch_option);
  54.  
  55. MikeData << "\nInputted String";
  56. MikeData << "\n\n************************************\n\n" << st_line;
  57. MikeData << "\n\nNumber of a's: " << i_va;
  58. MikeData << "\nNumber of e's: " << i_ve;
  59. MikeData << "\nNumber of i's: " << i_vi;
  60. MikeData << "\nNumber of o's: " << i_vo;
  61. MikeData << "\nNumber of u's: " << i_vu;
  62. MikeData << "\nTotal Vowels: " << i_vowel;
  63. MikeData << "\n\nNumber of Letters: " << i_letters;
  64.  
  65. cout << " End of Program";
  66.  
  67. HopeData.close();
  68. MikeData.close();
  69. }
  70.  
  71. void vowels()
  72. {
  73. while((ch_char = st_line[x++]) != '\0')
  74. switch(ch_char)
  75. {
  76. case 'a': case 'A':
  77. i_va++;
  78. break;
  79. case 'e': case 'E':
  80. i_ve++;
  81. break;
  82. case 'i': case 'I':
  83. i_vi++;
  84. break;
  85. case 'o': case 'O':
  86. i_vo++;
  87. break;
  88. case 'u': case 'U':
  89. i_vu++;
  90. break;
  91. }
  92. i_vowel = i_va + i_ve + i_vi + i_vo + i_vu;
  93. }
  94.  
  95. void letter()
  96. {
  97. for(x=0;x<500;x++)
  98. if(st_line[i_letters] == ' ' || st_line[i_letters] == '\0')
  99. i_count--;
  100. while(st_line[i_letters] != '\0')
  101. {
  102. if(st_line[i_letters++] != ' ' && (st_line[i_letters++] != ' ' && st_line[i_letters++] != '\0'))
  103. i_count++;
  104. i_letters++;
  105. }
Last edited by alc6379; Nov 30th, 2004 at 5:41 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
hopeolicious is offline Offline
43 posts
since Oct 2004
Nov 30th, 2004
0

Re: Can Someone Tell me why my program does not run

I'd need the complete code to get it to compile. And if you want anyone to take a really good look at code, use [CODE][/CODE] tags.

But why do you have a strangely worded loop here?
while ( st_line[x] != '\0' );
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Dec 1st, 2004
0

Re: Can Someone Tell me why my program does not run

that's likely the problem. There's only 1 possibility for that not to be an infinite loop in which case the loop terminates immediately.
It's also an empty loop...

Most likely the semicolon shouldn't be there and some braces were forgotten.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: EASY question? checking for line feed (return) in a html file with C++
Next Thread in C++ Forum Timeline: octal conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC