Merhabalar, lab dersinde hoca 8 tane kod ödevi verdi ben de Visual Studio üzerinden teker teker yapıyordum. Daha sonra 4. ödeve gelince input almadan programın sonuna gitti. Aynı kod parçasını başka bir projede deneyince kod sorunsuz çalıştı. Hoca tek bir Main'de istediği için yapmam gerekiyor. Yardım eder misiniz?
Tabii atarım ama kod yaklaşık 110 satır. Kodla ilgili bir problem olduğunu düşünmediğim için atmadım , çünkü kodu başka bir projede çalıştırınca, sorunsuz çalışıyor. Ancak tek bir main'de dediğim gibi alt alta yapınca input almıyor alt satıra geçiyor. cout ile ekrana çıktı atasam ekranda o çıktı gözüküyor ama girdi almıyor.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
// Klavyeden bir kelimenin, girilen bir cümlede kaç kez tekrar ettiğini bulan programı yazınız.
string words;
vector <string> sentence;
string searchletter;
cout << string(40, '*') << endl;
cout << "Enter the word you're searching for..." << endl;
cin >> searchletter;
int counter = 0;
cout << "Enter a sentence.. ( to finish your sentence press enter then ctrl+Z )" << endl;
while (cin>>words)
{
sentence.push_back(words);
}
int sensize = sentence.size();
for (int i = 0; i < sensize; i++)
{
if (sentence==searchletter)
{
counter++;
}
}
if (counter==0)
{
cout << "There is no (" << searchletter << ") in your sentence" << endl;
goto here;
}
cout << "There are " << counter << " times the word (" << searchletter << ") in your sentence" << endl;
here:
//İki boyutlu bir dizinin her satırının ve her sütununun toplamlarını ayrı ayrı hesaplayan ve bulduğu sonuçları ekranda görüntüleyen programı yazınız.
cout << "\n"<<string(40, '*') << endl;
int dizi[3][4] = { {1,9,0,3},{1,8,8,1},{1,9,2,3} };
int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
cout << "\nThe matrix that exist at first place:\n";
for (int i = 0; i < 3; i++) {
cout << i + 1 << "\t\t";
for (int j = 0; j < 4; j++)
{
cout << dizi[j] << "\t";
}
cout << endl;
}
for (int i = 0; i < 3; i++)
{
c1 += dizi[0];
c2 += dizi[1];
c3 += dizi[2];
c4 += dizi[3];
}
int sonuc[4] = { c1,c2,c3,c4 };
cout << "Summation =\t";
for (int i = 0; i < 4; i++)
{
cout << sonuc << "\t";
}
cout << endl;
system("Pause");
cout <<"\n"<< string(40, '*') << endl;
// 0’dan klavyeden girilen sayıya kadar olan sayılardan; tek olanları tek sayılar dizisine, çift olanları çift sayılar dizisine saklayan ve bu dizileri ayrı ayrı ekrana yazdıran programı yazınız.
int sayi;
cout << "Enter a number..." << endl;
cin >> sayi;// BURADA İNPUT ALMIYOR ALTINA BAŞKA İNPUT DA KOYSAM ALMIYOR
int teksayaç = 0, çiftsayaç = 0;
vector<int>çift;
vector<int>tek;
for (int i = 0; i <= sayi; i++)
{
if (i % 2 == 0)
{
çift.push_back(i);
çiftsayaç += i;
}
else
{
tek.push_back(i);
teksayaç += i;
}
}
int çiftadet = çift.size();
int tekadet = tek.size();
if (sayi == 0)
{
cout << "There is one even number =" << sayi << endl;
return 1;
}
cout << "Even numbers are...\t";
for (int i = 0; i < çiftadet; i++)
{
cout << çift << " ";
}
cout << "\nSummation of the numbers: " << çiftsayaç << endl;
cout << "Odd numbers are...\t";
for (int i = 0; i < tekadet; i++)
{
cout << tek << " ";
}
cout << "\nSummation of the numbers: " << teksayaç << endl;
return 1903;