Hi! I'm a beginner in programming and I am in a principles of programming class. The requirements are that I use Dev C++ to compile and run the programming problems for the homework. This is the problem I am working on with the pseudocode:
The Daily Trumpet newspaper accepts classified advertisements in 15 categories such as Apartments for Rent and Pets for Sale.
Develop the logic for a program that accepts classified advertising data, including category code (an integer 1 through 15) and number of words in the ad. Store these values in parallel arrays. Then sort the arrays so that records are in ascending order by category. The output lists each category, the number of ads in each category, and the total number of words in the ads in each category.
Code:
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
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; numads - 1;)
{
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; numads - 2;)
{
for (j = 0; 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;
}
}
}
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: ",adcatcode[k-1], " ","Word Count: ",subtotal;
}
else
{
cout<< "Number adds requested less than 1 or is too large; ad limit is ", MAXADS;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Everything compiles fine until I add the else statement. Also if I remove the else statement it compiles and runs but keeps me in the loop asking for the advertisement category code and the number of words for the advertisement. The errors I am getting once I add the else statement are :
PLD Ch8 7a.cpp: In function `int main(int, char**)':
PLD Ch8 7a.cpp:59: error: expected primary-expression before "else"
PLD Ch8 7a.cpp:59: error: expected `;' before "else"
PLD Ch8 7a.cpp: At global scope:
PLD Ch8 7a.cpp:64: error: expected constructor, destructor, or type conversion before '(' token
PLD Ch8 7a.cpp:64: error: expected `,' or `;' before '(' token
PLD Ch8 7a.cpp:65: error: expected unqualified-id before "return"
PLD Ch8 7a.cpp:65: error: expected `,' or `;' before "return"
PLD Ch8 7a.cpp:66: error: expected declaration before '}' token
make.exe: *** ["PLD Ch8 7a.o"] Error 1
Execution terminated
Any help is very much appreciated!! And sorry it is so long I just wanted to give as much info as possible.