I made a program which divides two variables suppose a & b, reads from a text file, but this on a loop coz I wanted to divide these variables 'till it got a quotient of 1, this only applicable for a number that is divisible, and if not divisible it would indicate/prints "Invalid". So far this all Ive got for I am already stuck. Hope someone could give me an advice how to do this.
inside my textfile mytxt.txt. It has one space between two numbers every lines.
27 3
40 4
1000 5
625 5
heres what ive got so far in my code
#include <iostream>
#include <fstream>
int main() {
std::ifstream file("mytxt.txt");
if ( file.eof()) return 0;
int a, b, cnt=0;
while (!file.eof()) {
file>>a>>b;
loop:
std::cout<<a << " ";
a/=b;
if(a%b == cnt)
goto loop;
std::cout<<"\n";
}
file.close();
system("pause");
}
output of this is
27 9 3
40
1000 200 40
625 125 25 5
Press any key to continue . . .
but it should be like this
27 9 3 1
Invalid
Invalid
625 125 25 5 1
it should have 3/3 to have 1 in the last. What should I have in my code to do this and insert a condition that if its not divisible, it prints "Invalid". thanks in advance. pls excuse my grammar.