0

Having some typing issues on compiler practice as c++

Hi so when I try rewriting the practice session in the C++ compiler for the practice Fluffy pancakes because it says to "declare i" somewhere before the condition statement. Tried using int i, didn't do anything. So I'll need help. P.S Also when I'm on the desktop it just wiped out complier practice when try editing the coding. There is another issue but I just refresh the page lol.

6th Sep 2024, 3:24 AM
David
David - avatar
6 Réponses
+ 2
a range-based for loop is a good alternative if you want a concise way to iterate arrays. for (const auto b : breakfasts){ cout << b << endl; } https://en.cppreference.com/w/cpp/language/range-for
10th Sep 2024, 2:52 AM
Bob_Li
Bob_Li - avatar
+ 1
Oh thanks! I like things to be concise. Other than that I'll just read keywords.
10th Sep 2024, 2:14 AM
David
David - avatar
+ 1
Oh ok thanks Bob
11th Sep 2024, 10:58 AM
David
David - avatar
0
can we see your code?
6th Sep 2024, 6:28 AM
Bob_Li
Bob_Li - avatar
0
#include <iostream> using namespace std; int main() { string breakfasts[] = {"Cinnamon Doughnuts", "Waffles", "Granola", "Chorizo Burrito", "French Toast"}; string newItem = "Fluffy Pancakes"; int index; cin >> index; breakfasts [index] = newItem; for (i = 0; i <= 4; i++){ cout << breakfasts << endl; } }
6th Sep 2024, 2:41 PM
David
David - avatar
0
you are missing the datatype of i in your for loop. you are also missing the indexing for breakfasts. for(int i = 0; i <=4; i++){ ⬆️this ⬇️ also this cout << breakfasts[i] << endl; }
6th Sep 2024, 3:32 PM
Bob_Li
Bob_Li - avatar