I have random number guessing game, it works except for one lag - after input number it wouldnt stop printing "Cipars ir mazaks" or "cipars ir lielaks" (number is smaller, number is larger), it just prints ant prints, if i put break after cout text, it stops running programm completely ofcourse, maby someone can test this and its just an issue with my pc.
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <ctime>
usingnamespace std;
int main () {
int a, b;
srand (time(0));
a = rand() % 10 + 1;
cout << "Uzmini ciparu no 1 to 10!"; //puts? Never heard of it. cout is standard print statement
cin >> b;
do {
if (a<b) {
cout << "Cipars ir mazaks";}
if (a>b) {
cout << "cipars ir lielaks";}
} while (a!=b);
cout << "Apsveicu!";
cin.get(): // Never use system anything. It is slow and messy.
return 0;
}
Thanks, i did write it like this before, i did find puts is the same as cin when using <cstdio>, tried everything, believe its an pc issue or im using dev-c++ and it acts on every pc im using differently although the same version, maby just should use different compiler
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <ctime>
usingnamespace std;
int main () {
int a, b;
srand (time(0));
a = rand() % 10 + 1;
cout << "Uzmini ciparu no 1 to 10!";
cin >> b;
while (a ! b) {
if (a<b) {
cout << "Cipars ir mazaks";}
if (a>b) {
cout << "cipars ir lielaks";}
cin >> b
}
cout << "Apsveicu!";
cin.get():
return 0;
}
//solved it! This is how this works!
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
int main ()
{
int a, b;
srand (time(0));
a = rand() % 10 + 1;
cout << "Guess the number from 1 to 10!"<<endl;
cin >> b;
do{
if (a<b) {cout << "Number is smaller"<<endl;cin >> b;}
else if (a>b) {cout << "Number is larger"<<endl;cin >> b;}
} while (a!=b);
cout << "Congrats!!"<<endl;
system("pause");
return 0;
}