trying to get the program to run but there is an error in line 31 (expected primary expression before else) i dont know what to do

// Devin Southern
// COSC 112 - Spring 2009
// Dr Stone
// Lab 9
// This program will use loop to keep track of failing, passing and valid grades


#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    // Declaration Section
    char letter;
    int pass=0, fail=0, valid=0, all=0;
    ifstream indata;
    ofstream outdata;
    
    indata.open("letters.txt");
    outdata.open("letters_out.txt");
    
    // Input
    while (indata)
    {
    if (letter >='a' && letter <='d')
       pass++;
       all++;
       }
      else    (this is where the error is)
       if(letter >='d' || letter <='f')
      {
       fail++;
       
       valid=(pass+fail);
       {     
     else
       outdata<<letter<<endl;
       all++;
       
       indata>>letter;
       }
       
       outdata<<error<<endl;
       outdata<<"There are  "<<pass<<" passing grades"<<endl;
       outdata<<"There are  "<<fail<<" failing grades"<<endl;
       outdata<<"There are  "<<valid<<" valid grades"<<endl;
       outdata<<"There is a total of  "<<all<<" characters in the file"<<endl;
       
       outdata.close();
       return 0;
       }

Recommended Answers

All 2 Replies

you need some { and }s.

while (indata)
    {
    if (letter >='a' && letter <='d')
    {
       pass++;
       all++;
       }
      else    (this is where the error is)
       if(letter >='d' || letter <='f')
      {
       fail++;
       
       valid=(pass+fail);
       }     
     else
    {
       outdata<<letter<<endl;
       all++;
       indata>>letter;
       }

damn i had them all backwards and some missing...thanks man good looking out!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.