Purpose: To practice writing a simple well-documented (lots of comments) C++ program using
repetition structures (loops).

Assignment: The power of a repetition structure lies in the fact that a section of code can
be executed several times (often using different data) in the same program run.

Modify, Laboratory Assignment # 3 so that it will perform integer division using
different sets of values during a single program run. In each set, the first value is
the dividend and the second value is the divisor. You may use either a while or a
do-while sentinel-controlled repetition structure. A for structure may not be used.

Test your program by reading in integer values from a data file that I will send you.
The sentinel value is -99.

Be sure to print out the dividend and divisor values along with the quotient and
remainder for each set of values. The program output should go to a .dat output file
as well as to the computer monitor.

Dani AI

Generated

This thread needs a small, focused plan and a compact example that follows the lab rules: use a sentinel-controlled while/do-while loop (no for), read integer pairs from a data file, stop when the sentinel -99 appears, check for divide-by-zero, compute integer quotient and remainder, and write each result to both the console and a .dat output file. That approach builds on ’s interactive loop and on ’s suggestion to read from a file; it also answers and ’s repeated request to show working code (not just the assignment text).

Below is a concise, well-commented implementation that reads the first value of each pair as the dividend, treats -99 as the sentinel (first value), validates that a matching divisor exists, checks for zero, and writes a header plus one result row per input pair to both streams:

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main() {
    ifstream in("input.dat");           // change filename or use argv for flexibility
    ofstream out("results.dat");
    if (!in || !out) return 1;          // simple file-open check

    out << "Dividend\tDivisor\tQuotient\tRemainder\n";
    cout << "Dividend\tDivisor\tQuotient\tRemainder\n";

    int dividend;
    while (in >> dividend) {
        if (dividend == -99) break;    // sentinel found as first value
        int divisor;
        if (!(in >> divisor)) {         // missing pair: report and stop
            cerr << "Missing divisor for dividend " << dividend << "\n";
            break;
        }
        if (divisor == 0) {
            out << dividend << '\t' << divisor << '\t' << "ERROR(div0)\n";
            cout << dividend << '\t' << divisor << '\t' << "ERROR(div0)\n";
            continue;
        }
        int q = dividend / divisor;
        int r = dividend % divisor;
        out << dividend << '\t' << divisor << '\t' << q << '\t' << r << '\n';
        cout << dividend << '\t' << divisor << '\t' << q << '\t' << r << '\n';
    }
    return 0;
}

Notes and troubleshooting: confirm the sentinel’s position in the provided data file (if -99 might appear as the second value, check both positions), test with positive/negative inputs to see how the compiler reports quotient/remainder, and keep comments that explain variable roles and the loop sentinel logic (the lab asked for lots of comments). Posting the exact input file and any compiler errors (as requested earlier by ) will get faster, targeted debugging from responders.

Recommended Answers

All 10 Replies

So you want someone to do your homework for you.... I can help you write a division calculator with loops and stuff but i am not gonna write it for you..

So you want someone to do your homework for you.... I can help you write a division calculator with loops and stuff but i am not gonna write it for you..

That's fine... i need all the help i can get.

Funny thing is that you just copy pasted your assignment without even posting assignment #3 which is referred to in this one.

Post what you have so far (and not the original assignment #3) and say what you need help with.

Funny thing is that you just copy pasted your assignment without even posting assignment #3 which is referred to in this one.

Post what you have so far (and not the original assignment #3) and say what you need help with.

Here is Assignment 3
Assignment # 3 – if Selection Structures (Integer Division) -- modified

Purpose: To practice writing a simple well-documented (lots of comments) C++ program using the if and/or if/else selection structures.

Assignment: Computers are not able to properly calculate division problems that have a divisor of value 0. Modify, Laboratory Assignment # 2 so that it will test the value of the divisor before performing the integer division. In the case that the divisor is zero,the program should print an error message; otherwise, the program should perform the division.
Test your program by reading in any integer value for the dividend and zero (0) for the divisor.

I just said post your code and NOT just assignment #3.

Show us some effort that you actually tried to do this. Don't just copy and paste your homework! Programmers hate it and most likely no-one will help. Try to do it on your own and you you have any problems we will help you!

#include <iostream>

using namespace std;


int main(){

    char cDog;

    do{





        float div;
        float divs;

        cout << " Enter Num1: " << endl;
        cin >> div;
        cout << "Enter Num2: " << endl;
        cin >> divs;
        cout << div / divs << endl;
        cout << "WOuld You like to continue? Y/N: " << endl;
        cin >> cDog;

    }while (cDog == 'Y' || cDog == 'y');



    system("PAUSE");

    return 0;

}

This is a very basic C++ console div calculator i wrote up in about 3 min it uses a while loop this is i have time to write for you i am not writing a GUI

commented: code tags maybe? and where did GUI come from? -1

I just said post your code and NOT just assignment #3.

#include <iostream>

using namespace std;

int main() {
// Declare inputs
int dividend, divisor;
// Declare outputs
int quotient, remainder;

// Acquire the inputs
cout << "Please input the dividend: ";
cin >> dividend;
cout << "Please input the divisor: ";
cin >> divisor;

// Validate input
if ( divisor == 0 ) {
cout << "Error! Divide by zero!" << endl;
return -1;
}

// Calculate
quotient = dividend / divisor;
remainder = dividend - quotient * divisor;

// Output results
cout << "Quotient: " << quotient << endl;
cout << "Remainder: " << remainder << endl;

return 0;

You need to somehow determine what the input file is like through arguments or cin, and then write a loop around the calculations that reads the data from the file until the sentinel value is reached.

It looks to me like you just posted the code from that assignment #3 of yours and didn't even try at this one.

i have a presentation on this monday,i dont know what idea how should i present about the CAR PAR MACHINE..i must write it in C++..that progrm should have a looping,selection n sequence..someone please help me...give me an idea..huhuh

commented: Start by making your own thread, and improving your spelling. -1
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.