Skip to content

error while Compiling/running c code #192560

@gauravt-05

Description

@gauravt-05

Type: Bug

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
const int MIN = 1;
const int MAX = 5;
int guess;
int guesses;
int answer;

srand(time(0));

answer = rand() % MAX + MIN;

do{
printf("Enter your guess: ");
scanf("%d",&guess);
if(guess > answer)
{
printf("Too high!\n");
}
else if( guess < answer)
{
printf("Too low!\n");
}
else
{
printf("Correct! you got this\n");
}
guesses++;

}while(guess != answer);

printf("\n");
printf("Answer: %d\n",answer);
printf("Tries: %d\n",guesses);
printf("
");

return 0;

}

The result must provide me with the answer and the total amount of tries(guesses), I get the answer printed correctly but the number of tries isn't accurate, I tried running the same code on online compilers to see if my code had some problem, the online compilers gave me the correct answer and the number of tries but there seems to be something wrong with VSCode when it comes to the "tries" part

VS Code version: Code 1.82.0 (8b617bd, 2023-09-06T22:07:07.438Z)
OS version: Windows_NT x64 10.0.22621
Modes:

System Info
Item Value
CPUs AMD Ryzen 5 4600H with Radeon Graphics (12 x 2994)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.42GB (5.57GB free)
Process Argv --crash-reporter-id f807df9d-ec96-48b8-9397-90b59ddd654e
Screen Reader no
VM 0%
Extensions (5)
Extension Author (truncated) Version
code-runner for 0.12.0
cmake-tools ms- 1.15.31
cpptools ms- 1.17.5
cpptools-extension-pack ms- 1.3.0
cmake twx 0.0.17

(2 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30792226
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vscccc:30803845
282f8724:30602487
89544117:30613380
vscrpc:30673769
showlangstatbar:30737416
0bi6i642:30831757
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
asynctok:30821568
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572
dsvsc015:30829745

Metadata

Metadata

Assignees

Labels

*questionIssue represents a question, should be posted to StackOverflow (VS Code)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions