Question: Attached is my Pseudocode and my attempt at translating it into c++ code. I have errors at line 124. Please help me to clear my
Attached is my Pseudocode and my attempt at translating it into c++ code. I have errors at line 124. Please help me to clear my error.
// Pseudocode PLD Chapter 8 #7a pg. 366
// Start
//Declarations
//num MAXADS = 100
//num adcatcode[MAXADS]
//num adwords[MAXADS]
//num curCode
//num numads
//num i
//num j
//num k
//num subtotal
//num temp
//output "Please enter the number of ads: "
//input numads
//if ((numads > 0) and (numads <= MAXADS))
//for i = 0 to numads - 1
//output "Please enter Advertisement Category Code (1 - 15): "
//input adcatcode[i]
//output "Please enter number of words for the advertisement: "
//input adwords[i]
//endfor
//for i = 0 to numads - 2
//for j = 0 to numads - 2
//if (adcatcode[j] > adcatcode[j+1])
//temp = adcatcode[j]
//adcatcode[j] = adcatcode[j+1]
//adcatcode[j+1] = temp
//temp = adwords[j]
//adwords[j] = adwords[j+1]
//adwords[j+1] = temp
//endif
//endfor
//endfor
//output "Total Word Counts Sorted By Category Code"
//output "========================================="
//k = 0
//while k <= numads - 1
//subtotal = 0
//curCode = adcatcode[k]
//while ( (curCode = adcatcode[k]) and (k <= numads - 1) )
//subtotal = subtotal + adwords[k]
//k = k + 1
//endwhile
//output "Category: ",adcatcode[k - 1], "","Word Count: ", subtotal
//endwhile
//else
//output "Number adds requested less than 1 or is too large; ad limit is ",MAXADS
//endif
// Stop
#include
#include
using namespace std;
int main()
{
int MAXADS = 100;
int adcatcode[MAXADS];
int adwords[MAXADS];
int curCode;
int numads;
int i;
int j;
int k;
int subtotal;
int temp;
cout << "Please enter the number of ads: ";
cin >> numads;
{
if ((numads > 0) && (numads <= MAXADS))
{
for (i = 0; i <= numads-1; i++)
{
cout << "Please enter Advertisement Category Code (1 - 15): " ;
cin >> adcatcode[i];
cout << "Please enter number of words for the advertisement: ";
cin >> adwords[i];
}
{
for (i = 0; i <= numads-2; i++)
{
for (j = 0; j <= numads-2; j++)
{
if (adcatcode[j] > adcatcode[j+1])
temp = adcatcode[j];
adcatcode[j] = adcatcode[j+1];
adcatcode[j+1] = temp;
temp = adwords[j];
adwords[j] = adwords[j+1];
adwords[j+1] = temp;
}
}
}
{
cout << "Total Word Counts Sorted By Category Code" < cout << "=========================================" < } { k = 0; while (k <= numads-1) subtotal = 0; curCode = adcatcode[k]; { while ((curCode = adcatcode[k]) && (k <= numads - 1)) subtotal = subtotal + adwords[k]; k = k + 1; } { cout << "Category: " < } } else cout << "Number adds requested less than 1 or is too large; ad limit is "< } system ("PAUSE"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
