Harsh
And try with just cin.ignore()
Anonymous
Like 1 for int
Anonymous
And try with just cin.ignore()
I want to repetitively remind user to correct input after providing invalid data to prevent a fail state
Anonymous
And try with just cin.ignore()
Sure, that will also work but after wrong input the recursion doesn't work the way I want it to. It simply collects data infinitely
Harsh
You ignoring 100 inputs I guess
Anonymous
Yes, not really needed though and yours is just efficient
Anonymous
But how do I fix the infinite recursion
Harsh
But how do I fix the infinite recursion
Umm, looking at code, you want infinite recursion till stack overflow?
Anonymous
Umm, looking at code, you want infinite recursion till stack overflow?
That is just how it turned out. I simply want a recursion that allows a correction to be made and once done, moves on the the next statement if available
Pavel
Use return; if input is valid
there's else that makes it the same as if there was a return
Pavel
strangely this code works for me 🤔
Anonymous
If input is valid, everything works fine, but when input is invalid, recursion occurs infinitely
Pavel
the only issue I had is replacing /n to \n
Anonymous
the only issue I had is replacing /n to \n
Great, you fixed it. Thank you
Pavel
oh, OK 😅
Anonymous
Guess I confused the slashes
Anonymous
Thanks to everyone
Anonymous
And try with just cin.ignore()
I now also get yours as it simply works. Thanks too.
Anonymous
😊
Anonymous
Please help me! 🤕🤕
Anonymous
#include<iostream> using namespace std; int main() { int x, y, z; cout<<"enter x and y and z \n"; cin>>x>>y>>z; if (x>y && x>z) cout<< x <<"\n"; else if ( y>z ); cout<<y <<"\n"; else cout<<z<<" \n" ; return 0; }
Apk
Please help me! 🤕🤕
what is the issue?
Anonymous
The second if has a semi colon after ()
Anonymous
what is the issue?
Write a program to read three integer numbers then find and print the largest one among these numbers.
Al
logic is wrong
Anonymous
Fix the semi colon
Anonymous
Al
yes review the logic of comparisons it looks wrong
Anonymous
#include<iostream> using namespace std; int main() { int x, y, z; cout<<"enter x and y and z \n"; cin>>x>>y>>z; if (x>y && x>z) cout<< x <<"\n"; else if ( y>z ) cout<<y <<"\n"; else cout<<z<<" \n" ; return 0; }
Anonymous
Second if part; else if(y>z)- you added a semi colon
Anonymous
No problem
christian
/*MATRIX ARITHMETIC*/ #include <stdio.h> #include "conio.h" int main(int argv,char argc[]) { int x = 0; int y = 0; int i = 0; int j = 0; printf("MATRIX ARITHMETIC\n"); printf("Enter array dimension for the array row: "); scanf("%d", &x); printf("Enter array dimension for the array colum: "); scanf("%d", &y); int a[x][y]; int b[x][y]; int ad[x][y]; int mu[x][y]; //int di[x][y]; int su[x][y]; printf("Enter values for matrix '\A\': \n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("Array[%d][%d] = ", i, j); scanf("%d", &a[i][j]); } } printf("Enter values for matrix \'B\': \n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("b[%d][%d] = ", i, j); scanf("%d", &b[i][j]); } } printf("Matrix Addition\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { ad[i][j]=a[i][j]+b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d\t", ad[i][j]); } printf("\n"); } printf("Matrix Multiplication\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { mu[i][j]=a[i][j]*b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d\t", mu[i][j]); } printf("\n"); } /*printf("Matrix Division\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { di[i][j]=a[i][j]/b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d", di[i][j]); } printf("\n"); }*/ printf("Matrix Subtraction\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { su[i][j]=a[i][j]-b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d\t", su[i][j]); } printf("\n"); } getch(); return 0; }
Anyone help debug this code 😂😂😂😂 it has defeated me 😂😂😂😂
christian
/*MATRIX ARITHMETIC*/ #include <stdio.h> #include "conio.h" int main(int argv,char argc[]) { int x = 0; int y = 0; int i = 0; int j = 0; printf("MATRIX ARITHMETIC\n"); printf("Enter array dimension for the array row: "); scanf("%d", &x); printf("Enter array dimension for the array colum: "); scanf("%d", &y); int a[x][y]; int b[x][y]; int ad[x][y]; int mu[x][y]; //int di[x][y]; int su[x][y]; printf("Enter values for matrix '\A\': \n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("Array[%d][%d] = ", i, j); scanf("%d", &a[i][j]); } } printf("Enter values for matrix \'B\': \n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("b[%d][%d] = ", i, j); scanf("%d", &b[i][j]); } } printf("Matrix Addition\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { ad[i][j]=a[i][j]+b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d\t", ad[i][j]); } printf("\n"); } printf("Matrix Multiplication\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { mu[i][j]=a[i][j]*b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d\t", mu[i][j]); } printf("\n"); } /*printf("Matrix Division\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { di[i][j]=a[i][j]/b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d", di[i][j]); } printf("\n"); }*/ printf("Matrix Subtraction\n"); for(i=0;i<x;i++) { for(j=0;j<y;j++) { su[i][j]=a[i][j]-b[i][j]; } } for(i=0;i<x;i++) { for(j=0;j<y;j++) { printf("%d\t", su[i][j]); } printf("\n"); } getch(); return 0; }
It's <conio.h> not "conio.h"
محمود
#include <iostream> #include <algorithm> int main() { int list[3] = {10, 800, 8}; std::cout << *std::max_element(list, list+3); return 0; }
محمود
How can I have the user enter the values ..... cin
Igor🇺🇦
How can I have the user enter the values ..... cin
Why are you answering your own questions?🤷‍♂️
Logina
how can we write a program with while loop which ask the user to enter an integer 10 times and at the end display their sums and their products, I know how can I do it inside the loop but how to do it at the end??
Afosa
- VLA are optional and will impact your programs stability - I don't see any reason to use conio - commenting out code is pretty bad - you don't check for invalid inputs
Thanks very much bro, however I wasn't sure of that part of the code, hence the reason for the comment; so that the code can run smoothly. I will like to know the meaning of "VLA".
Afosa
It's <conio.h> not "conio.h"
Thanks but "conio.h" is also allowed. It implies that the preprocessor is inform that file conio is found in the current working directory.
Anonymous
Merry Christmas 🎄
Anonymous
Merry Christmas, guys! :)
Igor🇺🇦
Merry Christmas 🎄
First of all - it's off topic and second - most people in this group don't celebrate this holiday.
Anonymous
Merry Christmas 🎄
Anonymous
We're not here to read hundreds of sentences which are all the same and meaningless.
Anonymous
https://stackoverflow.com/questions/65453470/inputting-a-file-address-from-a-text-file-to-openssl-encryption-function-in-c Can anyone answer that?
temp
#include<iostream> #include<vector> #include<memory> class List{ private: int data; public: List(); List(int value); int get_data()const; ~List(); }; List::List() :data{0} {} List::List(int data) :data{data} { std::cout<<"\t value set to "<<data<<"\n"; } int List::get_data()const{ return data; } List::~List(){ std::cout<<" destructor is called for the data\t"<<data<<"\n"; } std::unique_ptr<std::vector<std::shared_ptr<List>>> make(){ return std::unique_ptr<std::vector<std::shared_ptr<List>>> (); } void fill(std::vector<std::shared_ptr<List>> &vec , int num){ for(int i{0};i<num;i++){ std::cout<<"enter the data \t"; int data{}; std::cin>>data; vec.push_back(std::make_shared<List>(data)); } } void display(const std::vector<std::shared_ptr<List>> &vec){ for(const auto &vecs : vec) std::cout<<vecs->get_data()<<"\t"; } int main(){ std::unique_ptr<std::vector<std::shared_ptr<List>>> head; head = make(); int num{}; std::cout<<"Enter the number of the data\t"; std::cin>>num; fill(*head,num); display(*head); return 0; }
temp
There is problem while fill method is called
temp
Can some one explain why vector does not push_back value.
Cat
make() returns a nullptr. It needs to return "std::make_unique<std::vector<std::shared_ptr<List>>>()".
temp
Thnx
Igor🇺🇦
This is not Linux support group.
Anonymous
Hello, can you help
Anonymous
Rewrite the following expression in C ++ Code and print it. a + b + c + d + e Algebra: C ++: = (a + b + c + d + e) ​​/ 5; If the parentheses are removed, we obtain a + b + c + d + e / 5, which evaluates incorrectly as: a + b + c + d +e/5
Anonymous
//m=A+B+C+D+E/5 #include <iostream> using namespace std; int main (){ int A, B, C , D , E , sum , m; cout <<"enter the A & B & C & D & E \n"; cin >>A>>B >>C>>D>>E ; sum = A + B + C + D + E ; m=sum/5; cout <<"_____________\n"; cout <<" m = "<< m;}
Anonymous
Is that True or false 😐😐
Junaid
Will some one please share an article about dependent and independent Operationing system
Igor🇺🇦
Will some one please share an article about dependent and independent Operationing system
Are you sure you've written it correctly? "independent Operationing system" ?
Hadaward 'Solly'
I just opened Silberschatz and nowhere he defines the category of '(in)dependent operating systems'
Igor🇺🇦
Device dependent & independent OS
Are you talking about OS-agnostic/cross-platform C/C++ code? https://linustechtips.com/topic/855181-how-to-write-truly-os-agnosticcross-platform-applications/
Ս
There is a system only having the following: - mutex lock - atomic_dec/atomic_inc (atomic operations) How we can realize rwlock using mutex lock and atomic operations (read write lock)? I need to: - describe count of mutex and atomic variables - describe logic of rwlock_readlock, rwlock_writelock functions
Anonymous
is there a way to use regex in kernel ?
Anonymous
https://paste.ubuntu.com/p/z6rzWcPP7z/
Anonymous
My program is showing I'd returned 1 exit status error Can someone help?