Skip to content

Code in not running #4215

@sakaldevverm

Description

@sakaldevverm

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: left
Actual value was -1.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)   
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

Screenshot

Screenshot (164)

Environment data

PS C:\Users\HP\Desktop\Coding\C++ Coding> cd "c:\Users\HP\Desktop\Coding\C++ Coding\BasicProgram\" ; if ($?) { g++ basicCode.cpp -o basicCode } ; if ($?) { .\basicCode }
basicCode.cpp:17:78: error: stray '\' in program
     $os = if ($IsLinux -or $IsMacOS) { uname -a } else { (dir $env:SystemRoot\System32\cmd.exe).VersionInfo.FileVersion }

                 ^
basicCode.cpp:17:87: error: stray '\' in program
     $os = if ($IsLinux -or $IsMacOS) { uname -a } else { (dir $env:SystemRoot\System32\cmd.exe).VersionInfo.FileVersion }

                          ^
basicCode.cpp:19:16: error: empty character constant
     Write-Host ''
                ^~
basicCode.cpp:27:16: error: empty character constant
     Write-Host ''
                ^~
basicCode.cpp:1:3: error: expected unqualified-id before '{' 
token
 & {
   ^
basicCode.cpp:1:3: error: expected constructor, destructor, or type conversion before '{' token
PS C:\Users\HP\Desktop\Coding\C++ Coding\BasicProgram>

Steps to reproduce

#include
using namespace std;

class Student{
string name;
int rollNo;
float marks[5];
public:
void input();
void show();
void tot_marks();
};

void Student::input(){
cout << "Enter name: ";
getline(cin, name);
cout << "Enter roll number: ";
cin >> rollNo;
cout << "Enter marks (5 subjects): ";
for(int i=0; i<5; i++){
cout << "Subject " << (i+1) << ": "; // to display subject number
cin >> marks[i];
}
}

void Student::show(){
cout << "Name: " << name << endl;
cout << "Roll number: " << rollNo << endl;
cout << "Marks: "<<endl;
for(int i=0; i<5; i++){
cout << "Subject " <<(i+1) << ": " << marks[i] << endl;
// cout << marks[i] << " ";
}
cout << endl;
}

void Student::tot_marks(){
float total = 0;
for(int i=0; i<5; i++){
total += marks[i];
}
cout << "Total marks: " << total;
}

int main(){
Student s;
s.input();
s.show();
s.tot_marks();
return 0;
}

Expected behavior

Screenshot (163)

Actual behavior

Uploading Screenshot (161).png…

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions