Can Someone Tell me why my program does not run

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 43
Reputation: hopeolicious is an unknown quantity at this point 
Solved Threads: 0
hopeolicious hopeolicious is offline Offline
Light Poster

Can Someone Tell me why my program does not run

 
0
  #1
Nov 30th, 2004
It is error free but it just doesnt cout for the user to continue or discontinue and it does now stop

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #2
Nov 30th, 2004
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' );
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

 
0
  #3
Dec 1st, 2004
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1659 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC